From 7b7d69a31e8632c00805b91e966b56d9908acd1b Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 19 Apr 2026 00:48:17 +0100 Subject: [PATCH] test: share restart health stopped-free fixture --- src/cli/daemon-cli/restart-health.test.ts | 49 +++++++++-------------- 1 file changed, 20 insertions(+), 29 deletions(-) diff --git a/src/cli/daemon-cli/restart-health.test.ts b/src/cli/daemon-cli/restart-health.test.ts index bc4a4d7c5db..d5438ce3eaf 100644 --- a/src/cli/daemon-cli/restart-health.test.ts +++ b/src/cli/daemon-cli/restart-health.test.ts @@ -88,6 +88,24 @@ async function inspectAmbiguousOwnershipWithProbe( }); } +async function waitForStoppedFreeGatewayRestart() { + const service = makeGatewayService({ status: "stopped" }); + inspectPortUsage.mockResolvedValue({ + port: 18789, + status: "free", + listeners: [], + hints: [], + }); + + const { waitForGatewayHealthyRestart } = await import("./restart-health.js"); + return waitForGatewayHealthyRestart({ + service, + port: 18789, + attempts: 120, + delayMs: 500, + }); +} + describe("inspectGatewayRestart", () => { beforeEach(() => { inspectPortUsage.mockReset(); @@ -252,21 +270,7 @@ describe("inspectGatewayRestart", () => { }); it("annotates stopped-free early exits with the actual elapsed time", async () => { - const service = makeGatewayService({ status: "stopped" }); - inspectPortUsage.mockResolvedValue({ - port: 18789, - status: "free", - listeners: [], - hints: [], - }); - - const { waitForGatewayHealthyRestart } = await import("./restart-health.js"); - const snapshot = await waitForGatewayHealthyRestart({ - service, - port: 18789, - attempts: 120, - delayMs: 500, - }); + const snapshot = await waitForStoppedFreeGatewayRestart(); expect(snapshot).toMatchObject({ healthy: false, @@ -280,21 +284,8 @@ describe("inspectGatewayRestart", () => { it("waits longer before stopped-free early exit on Windows", async () => { Object.defineProperty(process, "platform", { value: "win32", configurable: true }); - const service = makeGatewayService({ status: "stopped" }); - inspectPortUsage.mockResolvedValue({ - port: 18789, - status: "free", - listeners: [], - hints: [], - }); - const { waitForGatewayHealthyRestart } = await import("./restart-health.js"); - const snapshot = await waitForGatewayHealthyRestart({ - service, - port: 18789, - attempts: 120, - delayMs: 500, - }); + const snapshot = await waitForStoppedFreeGatewayRestart(); expect(snapshot).toMatchObject({ healthy: false,