11'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 ;
66
7- var agent = new Agent ( {
7+ const agent = new Agent ( {
88 keepAlive : true ,
99 keepAliveMsecs : 1000 ,
1010 maxSockets : 5 ,
1111 maxFreeSockets : 5
1212} ) ;
1313
14- var server = http . createServer ( function ( req , res ) {
14+ const server = http . createServer ( function ( req , res ) {
1515 if ( req . url === '/error' ) {
1616 res . destroy ( ) ;
1717 return ;
1818 } 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 ( ) {
2222 socket . end ( ) ;
23- } , 100 ) ;
23+ } ) ;
2424 }
2525 res . end ( 'hello world' ) ;
2626} ) ;
@@ -34,7 +34,7 @@ function get(path, callback) {
3434 } , callback ) ;
3535}
3636
37- var name = 'localhost:' + common . PORT + ':' ;
37+ const name = 'localhost:' + common . PORT + ':' ;
3838
3939function checkDataAndSockets ( body ) {
4040 assert . equal ( body . toString ( ) , 'hello world' ) ;
@@ -76,15 +76,15 @@ function remoteClose() {
7676 assert . equal ( agent . freeSockets [ name ] , undefined ,
7777 'freeSockets is not empty' ) ;
7878 remoteError ( ) ;
79- } , 200 ) ;
79+ } , common . platformTimeout ( 200 ) ) ;
8080 } ) ;
8181 } ) ;
8282 } ) ;
8383}
8484
8585function remoteError ( ) {
8686 // remove server will destroy ths socket
87- var req = get ( '/error' , function ( res ) {
87+ const req = get ( '/error' , function ( res ) {
8888 throw new Error ( 'should not call this function' ) ;
8989 } ) ;
9090 req . on ( 'error' , function ( err ) {
@@ -97,7 +97,7 @@ function remoteError() {
9797 assert . equal ( agent . sockets [ name ] , undefined ) ;
9898 assert . equal ( agent . freeSockets [ name ] , undefined ) ;
9999 done ( ) ;
100- } , 1 ) ;
100+ } , common . platformTimeout ( 1 ) ) ;
101101 } ) ;
102102}
103103
0 commit comments