@@ -46,6 +46,14 @@ describe("CronService - armTimer tight loop prevention", () => {
|
46 | 46 | .filter((d: unknown): d is number => typeof d === "number"); |
47 | 47 | } |
48 | 48 | |
| 49 | +function latestTimeoutHandle(timeoutSpy: ReturnType<typeof vi.spyOn>) { |
| 50 | +const result = timeoutSpy.mock.results.at(-1); |
| 51 | +if (!result || result.type !== "return") { |
| 52 | +throw new Error("Expected setTimeout to return a timer handle"); |
| 53 | +} |
| 54 | +return result.value; |
| 55 | +} |
| 56 | + |
49 | 57 | function createTimerState(params: { |
50 | 58 | storePath: string; |
51 | 59 | now: number; |
@@ -90,7 +98,7 @@ describe("CronService - armTimer tight loop prevention", () => {
|
90 | 98 | |
91 | 99 | armTimer(state); |
92 | 100 | |
93 | | -expect(state.timer).toEqual(expect.anything()); |
| 101 | +expect(state.timer).toBe(latestTimeoutHandle(timeoutSpy)); |
94 | 102 | const delays = extractTimeoutDelays(timeoutSpy); |
95 | 103 | |
96 | 104 | // Before the fix, delay would be 0 (tight loop). |
@@ -171,7 +179,7 @@ describe("CronService - armTimer tight loop prevention", () => {
|
171 | 179 | |
172 | 180 | armTimer(state); |
173 | 181 | |
174 | | -expect(state.timer).toEqual(expect.anything()); |
| 182 | +expect(state.timer).toBe(latestTimeoutHandle(timeoutSpy)); |
175 | 183 | const delays = extractTimeoutDelays(timeoutSpy); |
176 | 184 | expect(delays).toContain(60_000); |
177 | 185 | |
@@ -208,7 +216,7 @@ describe("CronService - armTimer tight loop prevention", () => {
|
208 | 216 | await onTimer(state); |
209 | 217 | |
210 | 218 | expect(state.running).toBe(false); |
211 | | -expect(state.timer).toEqual(expect.anything()); |
| 219 | +expect(state.timer).toBe(latestTimeoutHandle(timeoutSpy)); |
212 | 220 | |
213 | 221 | // The re-armed timer must NOT use delay=0. It should use at least |
214 | 222 | // MIN_REFIRE_GAP_MS to prevent the hot-loop. |
|