From d2b170ce585900e93528c548bfaf6a67304d2b03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel?= Date: Fri, 6 Nov 2026 21:46:53 +0000 Subject: [PATCH] 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 --- .../render/stages/captureStreamingStage.ts | 4 ++-- packages/studio/tests/chromeTestUtils.test.ts | 22 +++++++++++++++++++ packages/studio/tests/chromeTestUtils.ts | 6 ++++- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/packages/producer/src/services/render/stages/captureStreamingStage.ts b/packages/producer/src/services/render/stages/captureStreamingStage.ts index eaf7383d80..5c41f21f66 100644 --- a/packages/producer/src/services/render/stages/captureStreamingStage.ts +++ b/packages/producer/src/services/render/stages/captureStreamingStage.ts @@ -272,8 +272,8 @@ export function raceAgainstStall( } /** - * 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; diff --git a/packages/studio/tests/chromeTestUtils.test.ts b/packages/studio/tests/chromeTestUtils.test.ts index 5a4de9c981..700564fced 100644 --- a/packages/studio/tests/chromeTestUtils.test.ts +++ b/packages/studio/tests/chromeTestUtils.test.ts @@ -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"); diff --git a/packages/studio/tests/chromeTestUtils.ts b/packages/studio/tests/chromeTestUtils.ts index 16f0d43c6b..e517bc5ed1 100644 --- a/packages/studio/tests/chromeTestUtils.ts +++ b/packages/studio/tests/chromeTestUtils.ts @@ -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");