@@ -30,15 +30,16 @@ test(function serverTimeout(cb) {
30
30
var server = http . createServer ( function ( req , res ) {
31
31
// just do nothing, we should get a timeout event.
32
32
} ) ;
33
- server . listen ( common . PORT ) ;
33
+ server . listen ( common . mustCall ( function ( ) {
34
+ http . get ( { port : server . address ( ) . port } ) . on ( 'error' , function ( ) { } ) ;
35
+ } ) ) ;
34
36
var s = server . setTimeout ( 50 , function ( socket ) {
35
37
caughtTimeout = true ;
36
38
socket . destroy ( ) ;
37
39
server . close ( ) ;
38
40
cb ( ) ;
39
41
} ) ;
40
42
assert . ok ( s instanceof http . Server ) ;
41
- http . get ( { port : common . PORT } ) . on ( 'error' , function ( ) { } ) ;
42
43
} ) ;
43
44
44
45
test ( function serverRequestTimeout ( cb ) {
@@ -56,11 +57,13 @@ test(function serverRequestTimeout(cb) {
56
57
} ) ;
57
58
assert . ok ( s instanceof http . IncomingMessage ) ;
58
59
} ) ;
59
- server . listen ( common . PORT ) ;
60
- var req = http . request ( { port : common . PORT , method : 'POST' } ) ;
61
- req . on ( 'error' , function ( ) { } ) ;
62
- req . write ( 'Hello' ) ;
63
- // req is in progress
60
+ server . listen ( common . mustCall ( function ( ) {
61
+ var port = server . address ( ) . port ;
62
+ var req = http . request ( { port : port , method : 'POST' } ) ;
63
+ req . on ( 'error' , function ( ) { } ) ;
64
+ req . write ( 'Hello' ) ;
65
+ // req is in progress
66
+ } ) ) ;
64
67
} ) ;
65
68
66
69
test ( function serverResponseTimeout ( cb ) {
@@ -78,8 +81,10 @@ test(function serverResponseTimeout(cb) {
78
81
} ) ;
79
82
assert . ok ( s instanceof http . OutgoingMessage ) ;
80
83
} ) ;
81
- server . listen ( common . PORT ) ;
82
- http . get ( { port : common . PORT } ) . on ( 'error' , function ( ) { } ) ;
84
+ server . listen ( common . mustCall ( function ( ) {
85
+ var port = server . address ( ) . port ;
86
+ http . get ( { port : port } ) . on ( 'error' , function ( ) { } ) ;
87
+ } ) ) ;
83
88
} ) ;
84
89
85
90
test ( function serverRequestNotTimeoutAfterEnd ( cb ) {
@@ -104,8 +109,10 @@ test(function serverRequestNotTimeoutAfterEnd(cb) {
104
109
server . close ( ) ;
105
110
cb ( ) ;
106
111
} ) ;
107
- server . listen ( common . PORT ) ;
108
- http . get ( { port : common . PORT } ) . on ( 'error' , function ( ) { } ) ;
112
+ server . listen ( common . mustCall ( function ( ) {
113
+ var port = server . address ( ) . port ;
114
+ http . get ( { port : port } ) . on ( 'error' , function ( ) { } ) ;
115
+ } ) ) ;
109
116
} ) ;
110
117
111
118
test ( function serverResponseTimeoutWithPipeline ( cb ) {
@@ -125,12 +132,14 @@ test(function serverResponseTimeoutWithPipeline(cb) {
125
132
server . close ( ) ;
126
133
cb ( ) ;
127
134
} ) ;
128
- server . listen ( common . PORT ) ;
129
- var c = net . connect ( { port : common . PORT , allowHalfOpen : true } , function ( ) {
130
- c . write ( 'GET /1 HTTP/1.1\r\nHost: localhost\r\n\r\n' ) ;
131
- c . write ( 'GET /2 HTTP/1.1\r\nHost: localhost\r\n\r\n' ) ;
132
- c . write ( 'GET /3 HTTP/1.1\r\nHost: localhost\r\n\r\n' ) ;
133
- } ) ;
135
+ server . listen ( common . mustCall ( function ( ) {
136
+ var port = server . address ( ) . port ;
137
+ var c = net . connect ( { port : port , allowHalfOpen : true } , function ( ) {
138
+ c . write ( 'GET /1 HTTP/1.1\r\nHost: localhost\r\n\r\n' ) ;
139
+ c . write ( 'GET /2 HTTP/1.1\r\nHost: localhost\r\n\r\n' ) ;
140
+ c . write ( 'GET /3 HTTP/1.1\r\nHost: localhost\r\n\r\n' ) ;
141
+ } ) ;
142
+ } ) ) ;
134
143
} ) ;
135
144
136
145
test ( function idleTimeout ( cb ) {
@@ -158,9 +167,11 @@ test(function idleTimeout(cb) {
158
167
cb ( ) ;
159
168
} ) ;
160
169
assert . ok ( s instanceof http . Server ) ;
161
- server . listen ( common . PORT ) ;
162
- var c = net . connect ( { port : common . PORT , allowHalfOpen : true } , function ( ) {
163
- c . write ( 'GET /1 HTTP/1.1\r\nHost: localhost\r\n\r\n' ) ;
164
- // Keep-Alive
165
- } ) ;
170
+ server . listen ( common . mustCall ( function ( ) {
171
+ var port = server . address ( ) . port ;
172
+ var c = net . connect ( { port : port , allowHalfOpen : true } , function ( ) {
173
+ c . write ( 'GET /1 HTTP/1.1\r\nHost: localhost\r\n\r\n' ) ;
174
+ // Keep-Alive
175
+ } ) ;
176
+ } ) ) ;
166
177
} ) ;
0 commit comments