mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 07:50:13 +00:00
test(studio): kill and retry a test Chrome that hangs after it starts listening (#7337)
* test(studio): kill and retry a test Chrome that hangs after it starts listening * docs(producer): say the setup budget bounds each step, not setup as a whole
This commit is contained in:
@@ -272,8 +272,8 @@ export function raceAgainstStall<T>(
|
||||
}
|
||||
|
||||
/**
|
||||
* One budget for everything before a session's first frame: opening it, initializing it, and the
|
||||
* deferred drawElement init. Each call races against what is left of the same clock.
|
||||
* The setup budget for opening a session, initializing it, and the deferred drawElement init.
|
||||
* It bounds each step, not setup as a whole: the clock drops a step longer than its suspend gap.
|
||||
*/
|
||||
export function createSessionInitBudget(input: {
|
||||
frameIndex: number;
|
||||
|
||||
@@ -96,6 +96,28 @@ describe("launchTestChrome", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("kills and retries a launch that hangs after Chrome announced its DevTools address", async () => {
|
||||
vi.useFakeTimers();
|
||||
try {
|
||||
const { browser } = fakeBrowser(async () => undefined);
|
||||
const launch = vi
|
||||
.fn()
|
||||
.mockImplementationOnce(
|
||||
({ signal }: { signal?: AbortSignal }) =>
|
||||
new Promise((_, reject) =>
|
||||
signal?.addEventListener("abort", () => reject(new Error("Target closed"))),
|
||||
),
|
||||
)
|
||||
.mockResolvedValueOnce(browser);
|
||||
const launched = launchTestChrome(launch);
|
||||
await vi.advanceTimersByTimeAsync(20_000);
|
||||
await expect(launched).resolves.toBe(browser);
|
||||
expect(launch).toHaveBeenCalledTimes(2);
|
||||
} finally {
|
||||
vi.useRealTimers();
|
||||
}
|
||||
});
|
||||
|
||||
it("does not retry a launch that failed for another reason", async () => {
|
||||
const launch = vi.fn().mockRejectedValue(new Error("no such file"));
|
||||
await expect(launchTestChrome(launch)).rejects.toThrow("no such file");
|
||||
|
||||
@@ -28,8 +28,10 @@ export async function launchTestChrome(
|
||||
console.info(
|
||||
`[studio-test-chrome] launch ${attempt}/${LAUNCH_ATTEMPTS}: ${executablePath} (${version})`,
|
||||
);
|
||||
const killStuckLaunch = new AbortController();
|
||||
const deadline = setTimeout(() => killStuckLaunch.abort(), LAUNCH_TIMEOUT_MS);
|
||||
try {
|
||||
const browser = await launch(options);
|
||||
const browser = await launch({ ...options, signal: killStuckLaunch.signal });
|
||||
console.info(
|
||||
`[studio-test-chrome] launch ${attempt}/${LAUNCH_ATTEMPTS} ready after ${Date.now() - startedAt} ms`,
|
||||
);
|
||||
@@ -42,6 +44,8 @@ export async function launchTestChrome(
|
||||
);
|
||||
const stuck = error instanceof TimeoutError || elapsed >= LAUNCH_TIMEOUT_MS;
|
||||
if (!stuck || attempt === LAUNCH_ATTEMPTS) throw error;
|
||||
} finally {
|
||||
clearTimeout(deadline);
|
||||
}
|
||||
}
|
||||
throw new Error("Chrome launch attempts exhausted");
|
||||
|
||||
Reference in New Issue
Block a user