@@ -4,7 +4,7 @@ import { manifestSchema } from '@av/contracts';
44import { ApiClient , type PinnedBuild } from '@av/contracts/client' ;
55import { probeApi , readResponseBytes , validateHealthContract , verifyWorkerReadiness } from './smoke-api' ;
66
7- afterEach ( ( ) => vi . restoreAllMocks ( ) ) ;
7+ afterEach ( ( ) => { vi . useRealTimers ( ) ; vi . restoreAllMocks ( ) ; } ) ;
88
99const deploymentId = `${ 'a' . repeat ( 40 ) } -12345-2` ;
1010
@@ -46,10 +46,22 @@ describe('Worker readiness after deployment', () => {
4646 expect ( fetchImpl ) . toHaveBeenCalledTimes ( 2 ) ;
4747 } ) ;
4848
49+ it ( 'waits through a rollout that keeps serving the previous version for 25 seconds' , async ( ) => {
50+ vi . useFakeTimers ( ) ;
51+ const startedAt = Date . now ( ) ;
52+ const fetchImpl = vi . fn ( async ( ) => Response . json ( {
53+ ok : true , deploymentId : Date . now ( ) - startedAt >= 25_000 ? deploymentId : 'previous'
54+ } ) ) ;
55+ const ready = expect ( verifyWorkerReadiness ( { url, expectedDeploymentId : deploymentId , fetchImpl } ) ) . resolves . toBeUndefined ( ) ;
56+ await vi . advanceTimersByTimeAsync ( 25_000 ) ;
57+ await ready ;
58+ expect ( fetchImpl ) . toHaveBeenCalledTimes ( 6 ) ;
59+ } ) ;
60+
4961 it ( 'fails after the default bounded retries if the URL keeps serving a different deployment' , async ( ) => {
5062 const fetchImpl = vi . fn ( async ( ) => Response . json ( { ok : true , deploymentId : `${ 'b' . repeat ( 40 ) } -12345-2` } ) ) ;
5163 await expect ( verifyWorkerReadiness ( { url, expectedDeploymentId : deploymentId , fetchImpl, delayMs : 0 } ) ) . rejects . toThrow ( / W o r k e r r e a d i n e s s v e r i f i c a t i o n f a i l e d : .* e x p e c t e d W o r k e r d e p l o y m e n t m a r k e r / ) ;
52- expect ( fetchImpl ) . toHaveBeenCalledTimes ( 4 ) ;
64+ expect ( fetchImpl ) . toHaveBeenCalledTimes ( 13 ) ;
5365 } ) ;
5466
5567 it ( 'reports the final HTTP failure when readiness never succeeds' , async ( ) => {
0 commit comments