1
1
'use strict' ;
2
- require ( '../common' ) ;
2
+ const common = require ( '../common' ) ;
3
3
const assert = require ( 'assert' ) ;
4
4
const http = require ( 'http' ) ;
5
5
6
6
let complete ;
7
7
8
- const server = http . createServer ( function ( req , res ) {
8
+ const server = http . createServer ( ( req , res ) => {
9
9
// We should not see the queued /thatotherone request within the server
10
10
// as it should be aborted before it is sent.
11
11
assert . strictEqual ( req . url , '/' ) ;
@@ -19,10 +19,8 @@ const server = http.createServer(function(req, res) {
19
19
} ) ;
20
20
21
21
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 } ) ;
26
24
assert . strictEqual ( Object . keys ( agent . sockets ) . length , 0 ) ;
27
25
28
26
const options = {
@@ -34,7 +32,7 @@ server.listen(0, function() {
34
32
} ;
35
33
36
34
const req1 = http . request ( options ) ;
37
- req1 . on ( 'response' , function ( res1 ) {
35
+ req1 . on ( 'response' , ( res1 ) => {
38
36
assert . strictEqual ( Object . keys ( agent . sockets ) . length , 1 ) ;
39
37
assert . strictEqual ( Object . keys ( agent . requests ) . length , 0 ) ;
40
38
@@ -48,7 +46,9 @@ server.listen(0, function() {
48
46
assert . strictEqual ( Object . keys ( agent . sockets ) . length , 1 ) ;
49
47
assert . strictEqual ( Object . keys ( agent . requests ) . length , 1 ) ;
50
48
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 ) => {
52
52
// This is expected in response to our explicit abort call
53
53
assert . strictEqual ( err . code , 'ECONNRESET' ) ;
54
54
} ) ;
@@ -59,25 +59,16 @@ server.listen(0, function() {
59
59
assert . strictEqual ( Object . keys ( agent . sockets ) . length , 1 ) ;
60
60
assert . strictEqual ( Object . keys ( agent . requests ) . length , 1 ) ;
61
61
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 ( ) ) ;
70
63
71
- res1 . on ( 'end' , function ( ) {
72
- console . log ( 'Response ended.' ) ;
73
-
74
- setTimeout ( function ( ) {
64
+ res1 . on ( 'end' , common . mustCall ( ( ) => {
65
+ setTimeout ( common . mustCall ( ( ) => {
75
66
assert . strictEqual ( Object . keys ( agent . sockets ) . length , 0 ) ;
76
67
assert . strictEqual ( Object . keys ( agent . requests ) . length , 0 ) ;
77
68
78
69
server . close ( ) ;
79
- } , 100 ) ;
80
- } ) ;
70
+ } ) , 100 ) ;
71
+ } ) ) ;
81
72
} ) ;
82
73
83
74
req1 . end ( ) ;
0 commit comments