Skip to content

Commit dc5b188

Browse files
ericallamTrigger.dev RepoOps
authored andcommitted
test(run-store): make the recovery lease pending-age assertion deterministic
Mono-RevId: 5f6005ecb806ffb019fff13ec7a553ddaa1dcad2
1 parent d94ab29 commit dc5b188

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

‎internal-packages/run-store/src/redisSnapshotStore.recoveryLease.test.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ import { containerTest, redisTest } from "@internal/testcontainers";
22
import { createRedisClient } from "@internal/redis";
33
import { setTimeout as sleep } from "node:timers/promises";
44
import { Registry } from "prom-client";
5-
import { describe, expect } from "vitest";
5+
import { describe, expect, vi } from "vitest";
66
import { PendingIndex } from "./pendingIndex.js";
77
import {
88
PendingRecoveryWorker,
99
RecoverySweeper,
1010
type PostgresCommitStatus,
1111
} from "./pendingRecoveryWorker.js";
1212
import { RedisSnapshotStore, type SnapshotEntryInput } from "./redisSnapshotStore.js";
13+
import { runToPartition } from "./snapshotKeys.js";
1314
import { recoveryMetrics } from "./testFixtures/promMetrics.js";
1415

1516
// The single-fleet recovery lease, proven on real Redis: exactly one owner holds it, takeover happens
@@ -187,6 +188,11 @@ describe("RecoverySweeper pending gauges and the recovery lease", () => {
187188
});
188189
expect(prepared.outcome).toBe("prepared");
189190

191+
const { oldestMs } = await index.summary(runToPartition(runId));
192+
expect(oldestMs).toBeTypeOf("number");
193+
vi.useFakeTimers({ toFake: ["Date"] });
194+
vi.setSystemTime(oldestMs! + 1_000);
195+
190196
const worker = new PendingRecoveryWorker({
191197
store,
192198
pendingIndex: index,
@@ -259,6 +265,7 @@ describe("RecoverySweeper pending gauges and the recovery lease", () => {
259265
// The unit itself is still pending: only A's view of it was withdrawn.
260266
expect(await store.hasPreparedUnit(runId)).toBe(true);
261267
} finally {
268+
vi.useRealTimers();
262269
releaseTx();
263270
await held;
264271
await raw.quit();

0 commit comments

Comments
 (0)