Skip to content

Commit ae5e0e3

Browse files
spalladinoclaude
andcommitted
test(sequencer): add timing tests for CheckpointProposalJob
Adds timing tests for the CheckpointProposalJob that verify timing budgets and blocks built using a new `ManualDateProvider` so we mock advancing time. Tests the proposal job and timetable in coordination using mocked time for determinism. Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 9e1d53c commit ae5e0e3

File tree

4 files changed

+1075
-20
lines changed

4 files changed

+1075
-20
lines changed

yarn-project/foundation/src/timer/date.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,46 @@ export class TestDateProvider extends DateProvider {
3131
this.offset = timeMs - Date.now();
3232
this.logger.warn(`Time set to ${new Date(timeMs).toISOString()}`, { offset: this.offset, timeMs });
3333
}
34+
35+
/** Advances the time by the given number of seconds. */
36+
public advanceTime(seconds: number) {
37+
this.offset += seconds * 1000;
38+
}
39+
}
40+
41+
/**
42+
* A date provider for tests that only advances time via explicit advanceTime() calls.
43+
* Unlike TestDateProvider, this does NOT track real time progression - time is completely
44+
* frozen until explicitly advanced. This eliminates flakiness from tests taking
45+
* varying amounts of real time to execute.
46+
*/
47+
export class ManualDateProvider extends DateProvider {
48+
private currentTimeMs: number;
49+
50+
/**
51+
* @param initialTimeMs - Initial time in milliseconds. Defaults to a round timestamp for easy visualization.
52+
*/
53+
constructor(initialTimeMs: number = Date.UTC(2025, 0, 1, 0, 0, 0)) {
54+
super();
55+
this.currentTimeMs = initialTimeMs;
56+
}
57+
58+
public override now(): number {
59+
return this.currentTimeMs;
60+
}
61+
62+
/** Sets the current time to the given timestamp in milliseconds. */
63+
public setTime(timeMs: number) {
64+
this.currentTimeMs = timeMs;
65+
}
66+
67+
/** Advances the time by the given number of seconds. */
68+
public advanceTime(seconds: number) {
69+
this.currentTimeMs += seconds * 1000;
70+
}
71+
72+
/** Advances the time by the given number of milliseconds. */
73+
public advanceTimeMs(ms: number) {
74+
this.currentTimeMs += ms;
75+
}
3476
}

0 commit comments

Comments
 (0)