20
20
// USE OR OTHER DEALINGS IN THE SOFTWARE.
21
21
22
22
'use strict' ;
23
- require ( '../common' ) ;
23
+ const common = require ( '../common' ) ;
24
24
const assert = require ( 'assert' ) ;
25
25
const http = require ( 'http' ) ;
26
26
27
27
let complete ;
28
28
29
- const server = http . createServer ( function ( req , res ) {
29
+ const server = http . createServer ( ( req , res ) => {
30
30
// We should not see the queued /thatotherone request within the server
31
31
// as it should be aborted before it is sent.
32
32
assert . strictEqual ( req . url , '/' ) ;
@@ -40,10 +40,8 @@ const server = http.createServer(function(req, res) {
40
40
} ) ;
41
41
42
42
43
- server . listen ( 0 , function ( ) {
44
- console . log ( 'listen' , server . address ( ) . port ) ;
45
-
46
- const agent = new http . Agent ( { maxSockets : 1 } ) ;
43
+ server . listen ( 0 , ( ) => {
44
+ const agent = new http . Agent ( { maxSockets : 1 } ) ;
47
45
assert . strictEqual ( Object . keys ( agent . sockets ) . length , 0 ) ;
48
46
49
47
const options = {
@@ -55,7 +53,7 @@ server.listen(0, function() {
55
53
} ;
56
54
57
55
const req1 = http . request ( options ) ;
58
- req1 . on ( 'response' , function ( res1 ) {
56
+ req1 . on ( 'response' , ( res1 ) => {
59
57
assert . strictEqual ( Object . keys ( agent . sockets ) . length , 1 ) ;
60
58
assert . strictEqual ( Object . keys ( agent . requests ) . length , 0 ) ;
61
59
@@ -69,7 +67,9 @@ server.listen(0, function() {
69
67
assert . strictEqual ( Object . keys ( agent . sockets ) . length , 1 ) ;
70
68
assert . strictEqual ( Object . keys ( agent . requests ) . length , 1 ) ;
71
69
72
- req2 . on ( 'error' , function ( err ) {
70
+ // TODO(jasnell): This event does not appear to currently be triggered.
71
+ // is this handler actually required?
72
+ req2 . on ( 'error' , ( err ) => {
73
73
// This is expected in response to our explicit abort call
74
74
assert . strictEqual ( err . code , 'ECONNRESET' ) ;
75
75
} ) ;
@@ -80,25 +80,16 @@ server.listen(0, function() {
80
80
assert . strictEqual ( Object . keys ( agent . sockets ) . length , 1 ) ;
81
81
assert . strictEqual ( Object . keys ( agent . requests ) . length , 1 ) ;
82
82
83
- console . log ( `Got res: ${ res1 . statusCode } ` ) ;
84
- console . dir ( res1 . headers ) ;
85
-
86
- res1 . on ( 'data' , function ( chunk ) {
87
- console . log ( `Read ${ chunk . length } bytes` ) ;
88
- console . log ( ' chunk=%j' , chunk . toString ( ) ) ;
89
- complete ( ) ;
90
- } ) ;
83
+ res1 . on ( 'data' , ( chunk ) => complete ( ) ) ;
91
84
92
- res1 . on ( 'end' , function ( ) {
93
- console . log ( 'Response ended.' ) ;
94
-
95
- setTimeout ( function ( ) {
85
+ res1 . on ( 'end' , common . mustCall ( ( ) => {
86
+ setTimeout ( common . mustCall ( ( ) => {
96
87
assert . strictEqual ( Object . keys ( agent . sockets ) . length , 0 ) ;
97
88
assert . strictEqual ( Object . keys ( agent . requests ) . length , 0 ) ;
98
89
99
90
server . close ( ) ;
100
- } , 100 ) ;
101
- } ) ;
91
+ } ) , 100 ) ;
92
+ } ) ) ;
102
93
} ) ;
103
94
104
95
req1 . end ( ) ;
0 commit comments