@@ -348,6 +348,46 @@ describe('`delayConnection()`', () => {
348348 req . end ( )
349349 } )
350350
351+ it ( 'emits a timeout - with Agent.timeout' , done => {
352+ nock ( 'http://example.test' ) . get ( '/' ) . delayConnection ( 10000 ) . reply ( 200 , 'OK' )
353+
354+ const onEnd = sinon . spy ( )
355+ const agent = new http . Agent ( { timeout : 5000 } )
356+
357+ const req = http . request ( 'http://example.test' , { agent } , res => {
358+ res . once ( 'end' , onEnd )
359+ } )
360+
361+ req . on ( 'timeout' , function ( ) {
362+ expect ( onEnd ) . not . to . have . been . called ( )
363+ done ( )
364+ } )
365+
366+ req . end ( )
367+ } )
368+
369+ it ( 'emits a timeout - options.timeout takes precedence over Agent.timeout' , done => {
370+ nock ( 'http://example.test' ) . get ( '/' ) . delayConnection ( 10000 ) . reply ( 200 , 'OK' )
371+
372+ const onEnd = sinon . spy ( )
373+ const agent = new http . Agent ( { timeout : 30000 } )
374+
375+ const req = http . request (
376+ 'http://example.test' ,
377+ { agent, timeout : 5000 } ,
378+ res => {
379+ res . once ( 'end' , onEnd )
380+ }
381+ )
382+
383+ req . on ( 'timeout' , function ( ) {
384+ expect ( onEnd ) . not . to . have . been . called ( )
385+ done ( )
386+ } )
387+
388+ req . end ( )
389+ } )
390+
351391 it ( 'does not emit a timeout when timeout > delayConnection' , done => {
352392 const responseText = 'okeydoke!'
353393 const scope = nock ( 'http://example.test' )
0 commit comments