fix(browser): give the DevToolsActivePort wait one deadline owner (#2265)
* Single owner for the Chrome DevToolsActivePort startup deadline Cold Chrome startup tolerance was spelled three ways for one wait: the helper fell back to 15,000 ms, the runtime fixture lifecycle passed a literal 60,000, and the real-browser verifier kept a local 60,000 constant. A per-caller literal quietly changes how long a lane tolerates a cold browser before it fails, and the failure reported only elapsed_ms, so a reader could not see which ceiling was hit. Export BROWSER_DEVTOOLS_STARTUP_TIMEOUT_MS as the owner, use it for the helper fallback and both call sites, and report startup_timeout_ms in BrowserStartupError. A source guard keeps callers from restating the number. * Pin the DevToolsActivePort deadline guard to the startup call argument --------- Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { readFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { describe, expect } from "vitest";
|
||||
@@ -9,6 +10,7 @@ import {
|
||||
} from "../../support/process/processFixture.js";
|
||||
|
||||
import {
|
||||
BROWSER_DEVTOOLS_STARTUP_TIMEOUT_MS,
|
||||
BrowserStartupError,
|
||||
waitForBrowserDevtoolsPort,
|
||||
} from "../../../src/browser/BrowserProcessStartup.js";
|
||||
@@ -86,15 +88,68 @@ describe("browser process startup", () => {
|
||||
failure: "timeout",
|
||||
exitCode: null,
|
||||
signalCode: null,
|
||||
startupTimeoutMs: 20,
|
||||
});
|
||||
expect(String(failure)).toContain("stderr=<empty>");
|
||||
expect(String(failure)).toContain("startup_timeout_ms=20");
|
||||
} finally {
|
||||
child.kill("SIGKILL");
|
||||
expect(await waitForExit(child, 5_000)).toBe(true);
|
||||
}
|
||||
});
|
||||
|
||||
it("names the owner's deadline when a caller omits one", async ({
|
||||
processes,
|
||||
}) => {
|
||||
const root = await temporaryRoot();
|
||||
const child = processes.spawn(process.execPath, [
|
||||
"-e",
|
||||
"setTimeout(() => process.exit(3), 10)",
|
||||
]);
|
||||
|
||||
const failure = await waitForBrowserDevtoolsPort({
|
||||
child,
|
||||
executable: process.execPath,
|
||||
activePortPath: join(root, "DevToolsActivePort"),
|
||||
stderr: () => "owner default fixture",
|
||||
pollIntervalMs: 5,
|
||||
}).catch((cause: unknown) => cause);
|
||||
|
||||
expect(failure).toBeInstanceOf(BrowserStartupError);
|
||||
expect(failure).toMatchObject({
|
||||
failure: "exited",
|
||||
startupTimeoutMs: BROWSER_DEVTOOLS_STARTUP_TIMEOUT_MS,
|
||||
});
|
||||
expect(String(failure)).toContain(
|
||||
`startup_timeout_ms=${String(BROWSER_DEVTOOLS_STARTUP_TIMEOUT_MS)}`,
|
||||
);
|
||||
});
|
||||
|
||||
it("keeps one owner for the DevToolsActivePort deadline", async () => {
|
||||
expect(BROWSER_DEVTOOLS_STARTUP_TIMEOUT_MS).toBe(60_000);
|
||||
const callers = [
|
||||
"../../../scripts/verify-real-browser.mjs",
|
||||
"../../../scripts/lib/browser-runtime-fixture-lifecycle.mjs",
|
||||
];
|
||||
for (const caller of callers) {
|
||||
const source = await readFile(new URL(caller, import.meta.url), "utf8");
|
||||
expect(devtoolsPortDeadlines(source)).toEqual([
|
||||
["BROWSER_DEVTOOLS_STARTUP_TIMEOUT_MS"],
|
||||
]);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
const temporaryRoot = async (): Promise<string> => {
|
||||
return createTestTempDirectory("rea-browser-startup-");
|
||||
};
|
||||
|
||||
const devtoolsPortDeadlines = (source: string): string[][] => {
|
||||
const calls = /waitForBrowserDevtoolsPort\(\{(?<body>[\s\S]*?)\}\)/gu;
|
||||
const deadlines = /\btimeoutMs:\s*(?<value>[^\n,]+)/gu;
|
||||
return [...source.matchAll(calls)].map((call) =>
|
||||
[...String(call.groups?.body).matchAll(deadlines)].map((deadline) =>
|
||||
String(deadline.groups?.value).trim(),
|
||||
),
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user