From d815c8eac62ffe9ea825a97302b7b72a37bc674c Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Fri, 6 Mar 2026 01:07:06 -0500 Subject: [PATCH] Tests: stabilize cron wake-mode legacy-delivery coverage --- ...runs-one-shot-main-job-disables-it.test.ts | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/cron/service.runs-one-shot-main-job-disables-it.test.ts b/src/cron/service.runs-one-shot-main-job-disables-it.test.ts index c36da9fd5c7..4931bb8ae39 100644 --- a/src/cron/service.runs-one-shot-main-job-disables-it.test.ts +++ b/src/cron/service.runs-one-shot-main-job-disables-it.test.ts @@ -192,7 +192,8 @@ vi.mock("node:fs/promises", async (importOriginal) => { beforeEach(() => { fsState.entries.clear(); fsState.nowMs = 0; - fsState.fixtureCount = 0; + // Keep fixture paths monotonic across tests so late async writes from a + // previous CronService instance cannot collide with a recycled fake store. ensureDir(fixturesRoot); }); @@ -540,18 +541,14 @@ describe("CronService", () => { const job = await addWakeModeNowMainSystemEventJob(cron, { name: "wakeMode now waits" }); const runPromise = cron.run(job.id, "force"); - // `cron.run()` now persists the running marker before executing the job. - // Allow more microtask turns so the post-lock execution can start. - for (let i = 0; i < 500; i++) { - if (runHeartbeatOnce.mock.calls.length > 0) { - break; - } - // Let the locked() chain progress. - await Promise.resolve(); - } + // `cron.run()` executes after releasing the persistence lock, so wait for + // the heartbeat runner to observe the started job instead of hand-spinning + // microtasks. This keeps the assertion stable across runtimes. + await vi.waitFor(() => { + expect(runHeartbeatOnce).toHaveBeenCalledTimes(1); + expect(requestHeartbeatNow).not.toHaveBeenCalled(); + }); - expect(runHeartbeatOnce).toHaveBeenCalledTimes(1); - expect(requestHeartbeatNow).not.toHaveBeenCalled(); expectMainSystemEventPosted(enqueueSystemEvent, "hello"); expect(job.state.runningAtMs).toBeTypeOf("number");