From ec9b9c1cb175ee77611d05f2873db9ccd25341fe Mon Sep 17 00:00:00 2001 From: Vishal Rana Date: Sun, 25 Oct 2026 17:42:40 -0700 Subject: [PATCH] fix(ui): stop the app lifecycle tests racing their 500 ms launch deadline Every fixture gave startAppServer a 500 ms deadline that also covered starting Node. The wrong_pid and wrong_id tests relied on that deadline expiring after the child wrote its readiness file, so under full-suite load the child could still be starting when the launch timed out, and the test then failed reading started.json (#377). A launch directory is new, so a readiness record with another launch's id or pid can never become valid. startAppServer now rejects it at once instead of waiting for the deadline, the fixtures get a 30 s startup deadline that no test waits for, and a separate test covers the timeout path with a manager that never reports readiness. Closes #377 --- ui/host/e2e/support/app-lifecycle.test.ts | 13 ++++++++++--- ui/host/e2e/support/app-lifecycle.ts | 4 +++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/ui/host/e2e/support/app-lifecycle.test.ts b/ui/host/e2e/support/app-lifecycle.test.ts index 68d92c398..574aea5c4 100644 --- a/ui/host/e2e/support/app-lifecycle.test.ts +++ b/ui/host/e2e/support/app-lifecycle.test.ts @@ -28,11 +28,11 @@ async function fixture(mode = "ready") { writeFileSync(join(dir, "session.json"), "synthetic session"); const mode = ${JSON.stringify(mode)}; if (mode === "exit") process.exit(1); - writeFileSync(join(dir, "ready.json"), JSON.stringify({ id: mode === "wrong_id" ? "previous" : id, pid: mode === "wrong_pid" ? process.pid + 1 : process.pid, env: { FANOUT_E2E_STORAGE_STATE: join(dir, "session.json") } })); + if (mode !== "silent") writeFileSync(join(dir, "ready.json"), JSON.stringify({ id: mode === "wrong_id" ? "previous" : id, pid: mode === "wrong_pid" ? process.pid + 1 : process.pid, env: { FANOUT_E2E_STORAGE_STATE: join(dir, "session.json") } })); process.on("SIGTERM", () => { if (mode !== "stubborn") process.exit(0); }); setInterval(() => {}, 60000); `); - return { state, started, options: { command: [process.execPath, script], timeout: 500 } }; + return { state, started, options: { command: [process.execPath, script], timeout: 30_000 } }; } async function exists(path: string) { return stat(path).then(() => true, () => false); } function running(pid: number) { try { process.kill(pid, 0); return true; } catch { return false; } } @@ -55,7 +55,7 @@ it("stops the previous owned server and removes its session/data before replacem it.each(["wrong_pid", "wrong_id"])("rejects %s readiness and cleans up the failed launch", async mode => { const { state, started, options } = await fixture(mode); - await expect(startAppServer(state, options)).rejects.toThrow("Timed out waiting for the spawned seeded server"); + await expect(startAppServer(state, options)).rejects.toThrow("Seeded server reported readiness for another launch"); const instance = JSON.parse(await readFile(started, "utf8")); expect(running(instance.pid)).toBe(false); expect(await exists(instance.dir)).toBe(false); @@ -63,6 +63,13 @@ it.each(["wrong_pid", "wrong_id"])("rejects %s readiness and cleans up the faile expect(await exists(`${state}.instances`)).toBe(false); }); +it("times out and cleans up when the manager never reports readiness", async () => { + const { state, options } = await fixture("silent"); + await expect(startAppServer(state, { ...options, timeout: 200 })).rejects.toThrow("Timed out waiting for the spawned seeded server"); + expect(await exists(state)).toBe(false); + expect(await exists(`${state}.instances`)).toBe(false); +}); + it("cleans the registered instance and temporary directory when setup exits early", async () => { const { state, started, options } = await fixture("exit"); await expect(startAppServer(state, options)).rejects.toThrow("exited before readiness"); diff --git a/ui/host/e2e/support/app-lifecycle.ts b/ui/host/e2e/support/app-lifecycle.ts index 690cc197d..b455f9ed8 100644 --- a/ui/host/e2e/support/app-lifecycle.ts +++ b/ui/host/e2e/support/app-lifecycle.ts @@ -91,7 +91,9 @@ export async function startAppServer(path: string, { command = ["bun", manager], for (;;) { if (failed || child.exitCode !== null || child.signalCode !== null) throw new Error("Seeded server setup exited before readiness"); const candidate = await readJSON(join(dir, "ready.json")); - if (candidate?.id === id && candidate.pid === child.pid && candidate.env) { ready = candidate; break; } + // The launch directory is new, so another launch's readiness can never become valid. + if (candidate && (candidate.id !== id || candidate.pid !== child.pid)) throw new Error("Seeded server reported readiness for another launch"); + if (candidate?.env) { ready = candidate; break; } if (Date.now() >= deadline) throw new Error("Timed out waiting for the spawned seeded server"); await new Promise(resolve => setTimeout(resolve, 50)); }