From 7f6fcbf637f71cb71fbf850e2fdcd1be411d676c Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 20 Jan 2026 06:56:10 +0000 Subject: [PATCH] fix: stabilize update.run test --- src/gateway/server.update-run.test.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/gateway/server.update-run.test.ts b/src/gateway/server.update-run.test.ts index 202ddc1d9..3c300a5f0 100644 --- a/src/gateway/server.update-run.test.ts +++ b/src/gateway/server.update-run.test.ts @@ -22,9 +22,17 @@ import { installGatewayTestHooks(); +async function waitForSignal(check: () => boolean, timeoutMs = 2000) { + const start = Date.now(); + while (Date.now() - start < timeoutMs) { + if (check()) return; + await new Promise((resolve) => setTimeout(resolve, 10)); + } + throw new Error("timeout"); +} + describe("gateway update.run", () => { it("writes sentinel and schedules restart", async () => { - vi.useFakeTimers(); const sigusr1 = vi.fn(); process.on("SIGUSR1", sigusr1); @@ -49,7 +57,7 @@ describe("gateway update.run", () => { ); expect(res.ok).toBe(true); - await vi.advanceTimersByTimeAsync(0); + await waitForSignal(() => sigusr1.mock.calls.length > 0); expect(sigusr1).toHaveBeenCalled(); const sentinelPath = path.join(os.homedir(), ".clawdbot", "restart-sentinel.json"); @@ -63,6 +71,5 @@ describe("gateway update.run", () => { ws.close(); await server.close(); process.off("SIGUSR1", sigusr1); - vi.useRealTimers(); }); });