@@ -620,9 +620,19 @@ describe("cron cli", () => {
620620 } ,
621621 ) ;
622622
623- it ( "reduces each history RPC timeout as the cron run wait budget elapses" , async ( ) => {
623+ it . each ( [
624+ { name : "without a system clock jump" , clockJumpMs : 0 } ,
625+ { name : "after the system clock jumps forward" , clockJumpMs : 3_600_000 } ,
626+ { name : "after the system clock jumps backward" , clockJumpMs : - 3_600_000 } ,
627+ ] ) ( "reduces each history RPC timeout $name" , async ( { clockJumpMs } ) => {
624628 vi . useFakeTimers ( ) ;
625- vi . setSystemTime ( new Date ( "2026-07-27T12:00:00.000Z" ) ) ;
629+ const monotonicNow = performance . now . bind ( performance ) ;
630+ let monotonicSample = 0 ;
631+ vi . spyOn ( performance , "now" ) . mockImplementation (
632+ ( ) => monotonicNow ( ) + ++ monotonicSample / 1_000 ,
633+ ) ;
634+ const startedAt = new Date ( "2026-07-27T12:00:00.000Z" ) ;
635+ vi . setSystemTime ( startedAt ) ;
626636
627637 const pendingRun = runCronRunAndCaptureExit ( {
628638 enqueued : true ,
@@ -644,6 +654,7 @@ describe("cron cli", () => {
644654 expect ( callGatewayFromCli . mock . calls . filter ( ( [ method ] ) => method === "cron.runs" ) ) . toHaveLength (
645655 1 ,
646656 ) ;
657+ vi . setSystemTime ( new Date ( startedAt . getTime ( ) + clockJumpMs ) ) ;
647658 await vi . advanceTimersByTimeAsync ( 25 ) ;
648659
649660 const { calls, exitSpy, runOpts } = await pendingRun ;
@@ -654,6 +665,7 @@ describe("cron cli", () => {
654665 expect ( exitSpy ) . toHaveBeenCalledWith ( 0 ) ;
655666 expect ( runOpts . timeout ) . toBe ( "600000" ) ;
656667 expect ( pollTimeouts ) . toHaveLength ( 2 ) ;
668+ expect ( pollTimeouts . every ( Number . isSafeInteger ) ) . toBe ( true ) ;
657669 expect ( pollTimeouts [ 0 ] ) . toBeLessThanOrEqual ( 100 ) ;
658670 expect ( pollTimeouts [ 1 ] ) . toBeLessThanOrEqual ( 75 ) ;
659671 expect ( pollTimeouts [ 1 ] ) . toBeLessThan ( pollTimeouts [ 0 ] ?? 0 ) ;
0 commit comments