Skip to content

Commit 8fd7542

Browse files
fix(cli): installing Chrome on a busy Windows PC no longer takes ten minutes (#7301)
* fix(cli): installing Chrome on a busy Windows PC no longer takes ten minutes * fix(cli): the priority reason lives in the PR, one helper sets either priority
1 parent 6011d9d commit 8fd7542

2 files changed

Lines changed: 38 additions & 5 deletions

File tree

‎packages/cli/src/renderSetupWorker.priority.test.ts‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ vi.mock("node:os", async (importOriginal) => ({
77
setPriority: os.setPriority,
88
}));
99
vi.mock("./utils/lintProject.js", () => ({ lintProject: vi.fn(async () => ({ ok: true })) }));
10+
vi.mock("./browser/installRun.js", () => ({
11+
runBrowserInstall: vi.fn(async () => ({ ok: true })),
12+
}));
1013

1114
beforeEach(() => {
1215
vi.resetModules();
@@ -39,6 +42,33 @@ it("a render's lint keeps normal priority", async () => {
3942
expect(write).toHaveBeenCalledWith(expect.stringContaining('{"ok":true}'));
4043
});
4144

45+
// fails without the fix: at normal priority, each write of the download queues behind a busy PC's work.
46+
it("the Chrome install runs one step above normal priority", async () => {
47+
process.argv[2] = "browser-install";
48+
process.env.HYPERFRAMES_RENDER_SETUP_INPUT = "{}";
49+
const write = vi.spyOn(process.stdout, "write").mockImplementation(() => true);
50+
51+
await import("./renderSetupWorker.js");
52+
53+
expect(os.setPriority).toHaveBeenCalledWith(constants.priority.PRIORITY_ABOVE_NORMAL);
54+
expect(write).toHaveBeenCalledWith(expect.stringContaining('{"ok":true}'));
55+
});
56+
57+
it("the Chrome install still runs when the system refuses the higher priority", async () => {
58+
process.argv[2] = "browser-install";
59+
process.env.HYPERFRAMES_RENDER_SETUP_INPUT = "{}";
60+
os.setPriority.mockImplementation(() => {
61+
throw nodeSystemErrorWithOsCodeInInfo("EACCES");
62+
});
63+
const write = vi.spyOn(process.stdout, "write").mockImplementation(() => true);
64+
const warn = vi.spyOn(process.stderr, "write").mockImplementation(() => true);
65+
66+
await import("./renderSetupWorker.js");
67+
68+
expect(write).toHaveBeenCalledWith(expect.stringContaining('{"ok":true}'));
69+
expect(warn).not.toHaveBeenCalled();
70+
});
71+
4272
const nodeSystemErrorWithOsCodeInInfo = (code: string) =>
4373
Object.assign(new Error(`A system error occurred: uv_os_setpriority returned ${code}`), {
4474
code: "ERR_SYSTEM_ERROR",

‎packages/cli/src/renderSetupWorker.ts‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,25 @@ const disposeSignalHandlers = installRenderSetupSignalHandlers(
2222

2323
const SANDBOX_REFUSED_PRIORITY = new Set(["EPERM", "EACCES"]);
2424

25-
function lowerPriority(): void {
25+
function setOwnPriority(priority: number, whatStaysNormal: string): void {
2626
try {
27-
setPriority(constants.priority.PRIORITY_LOW);
27+
setPriority(priority);
2828
} catch (error) {
2929
if (SANDBOX_REFUSED_PRIORITY.has((error as { info?: { code?: string } }).info?.code ?? ""))
3030
return;
31-
process.stderr.write(`Lint runs at normal priority: ${(error as Error).message}\n`);
31+
process.stderr.write(`${whatStaysNormal} at normal priority: ${(error as Error).message}\n`);
3232
}
3333
}
3434

3535
async function runMode(): Promise<unknown> {
3636
if (mode === "browser") return ensureBrowser(input);
37-
if (mode === "browser-install") return runBrowserInstall(input);
37+
if (mode === "browser-install") {
38+
setOwnPriority(constants.priority.PRIORITY_ABOVE_NORMAL, "The Chrome install runs");
39+
return runBrowserInstall(input);
40+
}
3841
if (mode === "lint") {
3942
// A background lint (Studio's, preview's) takes idle CPU only; a render waits on its lint, so that one does not.
40-
if (input.background) lowerPriority();
43+
if (input.background) setOwnPriority(constants.priority.PRIORITY_LOW, "Lint runs");
4144
return lintProject(
4245
input.projectDir,
4346
input.entryFile,

0 commit comments

Comments
 (0)