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)); }