11'use strict' ;
2- require ( '../common' ) ;
2+ const common = require ( '../common' ) ;
33const assert = require ( 'assert' ) ;
44const http = require ( 'http' ) ;
55
66let complete ;
77
8- const server = http . createServer ( function ( req , res ) {
8+ const server = http . createServer ( ( req , res ) => {
99 // We should not see the queued /thatotherone request within the server
1010 // as it should be aborted before it is sent.
1111 assert . strictEqual ( req . url , '/' ) ;
@@ -19,10 +19,8 @@ const server = http.createServer(function(req, res) {
1919} ) ;
2020
2121
22- server . listen ( 0 , function ( ) {
23- console . log ( 'listen' , server . address ( ) . port ) ;
24-
25- const agent = new http . Agent ( { maxSockets : 1 } ) ;
22+ server . listen ( 0 , ( ) => {
23+ const agent = new http . Agent ( { maxSockets : 1 } ) ;
2624 assert . strictEqual ( Object . keys ( agent . sockets ) . length , 0 ) ;
2725
2826 const options = {
@@ -34,7 +32,7 @@ server.listen(0, function() {
3432 } ;
3533
3634 const req1 = http . request ( options ) ;
37- req1 . on ( 'response' , function ( res1 ) {
35+ req1 . on ( 'response' , ( res1 ) => {
3836 assert . strictEqual ( Object . keys ( agent . sockets ) . length , 1 ) ;
3937 assert . strictEqual ( Object . keys ( agent . requests ) . length , 0 ) ;
4038
@@ -48,7 +46,9 @@ server.listen(0, function() {
4846 assert . strictEqual ( Object . keys ( agent . sockets ) . length , 1 ) ;
4947 assert . strictEqual ( Object . keys ( agent . requests ) . length , 1 ) ;
5048
51- req2 . on ( 'error' , function ( err ) {
49+ // TODO(jasnell): This event does not appear to currently be triggered.
50+ // is this handler actually required?
51+ req2 . on ( 'error' , ( err ) => {
5252 // This is expected in response to our explicit abort call
5353 assert . strictEqual ( err . code , 'ECONNRESET' ) ;
5454 } ) ;
@@ -59,25 +59,16 @@ server.listen(0, function() {
5959 assert . strictEqual ( Object . keys ( agent . sockets ) . length , 1 ) ;
6060 assert . strictEqual ( Object . keys ( agent . requests ) . length , 1 ) ;
6161
62- console . log ( `Got res: ${ res1 . statusCode } ` ) ;
63- console . dir ( res1 . headers ) ;
64-
65- res1 . on ( 'data' , function ( chunk ) {
66- console . log ( `Read ${ chunk . length } bytes` ) ;
67- console . log ( ' chunk=%j' , chunk . toString ( ) ) ;
68- complete ( ) ;
69- } ) ;
62+ res1 . on ( 'data' , ( chunk ) => complete ( ) ) ;
7063
71- res1 . on ( 'end' , function ( ) {
72- console . log ( 'Response ended.' ) ;
73-
74- setTimeout ( function ( ) {
64+ res1 . on ( 'end' , common . mustCall ( ( ) => {
65+ setTimeout ( common . mustCall ( ( ) => {
7566 assert . strictEqual ( Object . keys ( agent . sockets ) . length , 0 ) ;
7667 assert . strictEqual ( Object . keys ( agent . requests ) . length , 0 ) ;
7768
7869 server . close ( ) ;
79- } , 100 ) ;
80- } ) ;
70+ } ) , 100 ) ;
71+ } ) ) ;
8172 } ) ;
8273
8374 req1 . end ( ) ;
0 commit comments