File tree 1 file changed +20
-14
lines changed
1 file changed +20
-14
lines changed Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
2
3
3
const { expectsError, mustCall } = require ( '../common' ) ;
4
- const { Agent, get } = require ( 'http' ) ;
4
+ const { Agent, get, createServer } = require ( 'http' ) ;
5
5
6
6
// Test that the `'timeout'` event is emitted on the `ClientRequest` instance
7
7
// when the socket timeout set via the `timeout` option of the `Agent` expires.
8
8
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.
19
11
} ) ) ;
20
12
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