1
1
'use strict' ;
2
- var common = require ( '../common' ) ;
3
- var assert = require ( 'assert' ) ;
4
- var http = require ( 'http' ) ;
5
- var Agent = require ( '_http_agent' ) . Agent ;
2
+ const common = require ( '../common' ) ;
3
+ const assert = require ( 'assert' ) ;
4
+ const http = require ( 'http' ) ;
5
+ const Agent = require ( '_http_agent' ) . Agent ;
6
6
7
- var agent = new Agent ( {
7
+ const agent = new Agent ( {
8
8
keepAlive : true ,
9
9
keepAliveMsecs : 1000 ,
10
10
maxSockets : 5 ,
11
11
maxFreeSockets : 5
12
12
} ) ;
13
13
14
- var server = http . createServer ( function ( req , res ) {
14
+ const server = http . createServer ( function ( req , res ) {
15
15
if ( req . url === '/error' ) {
16
16
res . destroy ( ) ;
17
17
return ;
18
18
} else if ( req . url === '/remote_close' ) {
19
- // cache the socket, close it after 100ms
20
- var socket = res . connection ;
21
- setTimeout ( function ( ) {
19
+ // cache the socket, close it after a short delay
20
+ const socket = res . connection ;
21
+ setImmediate ( function ( ) {
22
22
socket . end ( ) ;
23
- } , 100 ) ;
23
+ } ) ;
24
24
}
25
25
res . end ( 'hello world' ) ;
26
26
} ) ;
@@ -34,7 +34,7 @@ function get(path, callback) {
34
34
} , callback ) ;
35
35
}
36
36
37
- var name = 'localhost:' + common . PORT + ':' ;
37
+ const name = 'localhost:' + common . PORT + ':' ;
38
38
39
39
function checkDataAndSockets ( body ) {
40
40
assert . equal ( body . toString ( ) , 'hello world' ) ;
@@ -76,15 +76,15 @@ function remoteClose() {
76
76
assert . equal ( agent . freeSockets [ name ] , undefined ,
77
77
'freeSockets is not empty' ) ;
78
78
remoteError ( ) ;
79
- } , 200 ) ;
79
+ } , common . platformTimeout ( 200 ) ) ;
80
80
} ) ;
81
81
} ) ;
82
82
} ) ;
83
83
}
84
84
85
85
function remoteError ( ) {
86
86
// remove server will destroy ths socket
87
- var req = get ( '/error' , function ( res ) {
87
+ const req = get ( '/error' , function ( res ) {
88
88
throw new Error ( 'should not call this function' ) ;
89
89
} ) ;
90
90
req . on ( 'error' , function ( err ) {
@@ -97,7 +97,7 @@ function remoteError() {
97
97
assert . equal ( agent . sockets [ name ] , undefined ) ;
98
98
assert . equal ( agent . freeSockets [ name ] , undefined ) ;
99
99
done ( ) ;
100
- } , 1 ) ;
100
+ } , common . platformTimeout ( 1 ) ) ;
101
101
} ) ;
102
102
}
103
103
0 commit comments