From 22615f8db8a82599c6d7717af7f89b0fa002f324 Mon Sep 17 00:00:00 2001 From: Bartek Igielski Date: Mon, 5 Oct 2026 21:45:42 +0200 Subject: [PATCH] test: align retention race fixture clocks - Use a shared timestamp for SQLite retention and the heartbeat write --- test/backend-test/heartbeat-data-plane.test.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/test/backend-test/heartbeat-data-plane.test.ts b/test/backend-test/heartbeat-data-plane.test.ts index d7e4f213..7acae53b 100644 --- a/test/backend-test/heartbeat-data-plane.test.ts +++ b/test/backend-test/heartbeat-data-plane.test.ts @@ -798,9 +798,12 @@ describe("heartbeat data plane", () => { }); test("retention cleanup racing a tracked write removes only expired data", async () => { - const { data, store } = await createRuntime("retention"); + // Retention uses SQLite's wall clock, so keep the fixture and calculator on the same clock. + const now = dayjs.utc(); + const { data, store } = await createRuntime("retention", now); await store.exec( - "INSERT INTO heartbeat (monitor_id, status, msg, time, important) VALUES (1, 0, 'expired', '2000-01-01 00:00:00', 1)" + "INSERT INTO heartbeat (monitor_id, status, msg, time, important) VALUES (1, 0, 'expired', ?, 1)", + [store.isoDateTimeMillis(now.subtract(31, "day"))] ); const coordinator = new DatabaseMaintenanceCoordinator(); const settings = { @@ -811,7 +814,7 @@ describe("heartbeat data plane", () => { }; await Promise.all([ - coordinator.run(() => data.write(heartbeat(store))), + coordinator.run(() => data.write(heartbeat(store, { time: store.isoDateTimeMillis(now) }))), coordinator.maintain(() => clearOldData(store, settings, data)), ]);