@@ -421,19 +421,29 @@ describe("provider error utils", () => {
421421 } ) ;
422422
423423 it ( "rejects stalled non-2xx error body read after chunk idle timeout" , async ( ) => {
424- const stream = new ReadableStream < Uint8Array > ( {
425- start ( controller ) {
426- controller . enqueue ( new TextEncoder ( ) . encode ( '{"error": {"message": "par' ) ) ;
427- } ,
428- } ) ;
429- const response = new Response ( stream , {
430- status : 502 ,
431- headers : { "content-type" : "application/json" } ,
432- } ) ;
424+ vi . useFakeTimers ( ) ;
425+ const setTimeoutSpy = vi . spyOn ( globalThis , "setTimeout" ) ;
426+ try {
427+ const stream = new ReadableStream < Uint8Array > ( {
428+ start ( controller ) {
429+ controller . enqueue ( new TextEncoder ( ) . encode ( '{"error": {"message": "par' ) ) ;
430+ } ,
431+ } ) ;
432+ const response = new Response ( stream , {
433+ status : 502 ,
434+ headers : { "content-type" : "application/json" } ,
435+ } ) ;
433436
434- await expect ( assertOkOrThrowProviderError ( response , "stalled-error" ) ) . rejects . toThrow (
435- "stalled-error (502)" ,
436- ) ;
437+ const assertion = expect (
438+ assertOkOrThrowProviderError ( response , "stalled-error" ) ,
439+ ) . rejects . toThrow ( "stalled-error (502)" ) ;
440+ await vi . advanceTimersByTimeAsync ( 0 ) ;
441+ expect ( setTimeoutSpy ) . toHaveBeenCalledWith ( expect . any ( Function ) , 10_000 ) ;
442+ await vi . advanceTimersByTimeAsync ( 10_000 ) ;
443+ await assertion ;
444+ } finally {
445+ vi . useRealTimers ( ) ;
446+ }
437447 } ) ;
438448
439449 it ( "proves idle timeout with a real TCP server that stalls mid-JSON-body" , async ( ) => {
0 commit comments