@@ -296,24 +296,17 @@ it('duplicate-mode setConnectionMode awaits an in-flight transition to the same
296296 localStoragePath : tmpRoot ,
297297 } ) ;
298298
299- // Make the offline transition's flush() defer to a later microtask so the
300- // offline -> streaming queue is still draining when the duplicate streaming
301- // call is issued. This exposes the early-return race deterministically.
299+ // Keeps the queue draining when p3 is issued, making the race deterministic.
302300 const flushSpy = jest
303301 . spyOn ( LDClientImpl . prototype , 'flush' )
304302 . mockImplementation ( ( ) => Promise . resolve ( { result : true } ) ) ;
305303
306- // Sequence: initial mode is 'streaming'. Go offline, then streaming, then
307- // streaming again (the duplicate). The third call's _connectionMode is already
308- // 'streaming' (set synchronously by the second call), so the idempotency guard
309- // fires. Without the await fix, p3 resolves before the second call's queued
310- // task has delegated 'streaming' to the data manager.
304+ // p3 hits the idempotency guard because p2 sets _connectionMode synchronously,
305+ // before p2's queued task runs. Without the await, p3 resolves too early.
311306 const p1 = client . setConnectionMode ( 'offline' ) ;
312307 const p2 = client . setConnectionMode ( 'streaming' ) ;
313308 const p3 = client . setConnectionMode ( 'streaming' ) ;
314309
315- // Awaiting only the duplicate call must guarantee the queued streaming
316- // transition has completed (mockSetConnectionMode called with 'streaming').
317310 await p3 ;
318311 expect ( mockSetConnectionMode ) . toHaveBeenCalledWith ( 'streaming' ) ;
319312
@@ -365,15 +358,16 @@ it('restores connection mode when an FDv2 offline transition task throws', async
365358 logger,
366359 localStoragePath : tmpRoot ,
367360 } ) ;
368- // Force the queued offline transition task to throw by making flush() reject.
361+ // flush() is the first async step, so a reject here means setConnectionMode
362+ // on the data manager is never reached.
369363 const flushSpy = jest
370364 . spyOn ( LDClientImpl . prototype , 'flush' )
371365 . mockRejectedValueOnce ( new Error ( 'flush failed' ) ) ;
372366
373367 await expect ( client . setConnectionMode ( 'offline' ) ) . rejects . toThrow ( 'flush failed' ) ;
374368
375- // The synchronously-set 'offline' must be rolled back to the prior mode so
376- // isOffline() does not lie while the data manager is still streaming .
369+ // The synchronously-set 'offline' is rolled back: the data manager is still
370+ // streaming, so isOffline() reflects actual state .
377371 expect ( client . getConnectionMode ( ) ) . toBe ( 'streaming' ) ;
378372 expect ( client . isOffline ( ) ) . toBe ( false ) ;
379373 // The data manager was never told to go offline.
0 commit comments