File tree Expand file tree Collapse file tree 1 file changed +20
-14
lines changed Expand file tree Collapse file tree 1 file changed +20
-14
lines changed Original file line number Diff line number Diff line change 11'use strict' ;
22
33const { expectsError, mustCall } = require ( '../common' ) ;
4- const { Agent, get } = require ( 'http' ) ;
4+ const { Agent, get, createServer } = require ( 'http' ) ;
55
66// Test that the `'timeout'` event is emitted on the `ClientRequest` instance
77// when the socket timeout set via the `timeout` option of the `Agent` expires.
88
9- const request = get ( {
10- agent : new Agent ( { timeout : 500 } ) ,
11- // Non-routable IP address to prevent the connection from being established.
12- host : '192.0.2.1'
13- } ) ;
14-
15- request . on ( 'error' , expectsError ( {
16- type : Error ,
17- code : 'ECONNRESET' ,
18- message : 'socket hang up'
9+ const server = createServer ( mustCall ( ( ) => {
10+ // Never respond.
1911} ) ) ;
2012
21- request . on ( 'timeout' , mustCall ( ( ) => {
22- request . abort ( ) ;
23- } ) ) ;
13+ server . listen ( ( ) => {
14+ const request = get ( {
15+ agent : new Agent ( { timeout : 500 } ) ,
16+ port : server . address ( ) . port
17+ } ) ;
18+
19+ request . on ( 'error' , expectsError ( {
20+ type : Error ,
21+ code : 'ECONNRESET' ,
22+ message : 'socket hang up'
23+ } ) ) ;
24+
25+ request . on ( 'timeout' , mustCall ( ( ) => {
26+ request . abort ( ) ;
27+ server . close ( ) ;
28+ } ) ) ;
29+ } ) ;
You can’t perform that action at this time.
0 commit comments