Skip to content

Commit 346f199

Browse files
aqrlnMylesBorins
authored andcommitted
test: refactor test-http(s)-set-timeout-server
* Make changes to `test-https-set-timeout-server` to resolve inconsistencies with its http counterpart: - Apply the changes analogous to those in GH-13802 to the https test. - Add a missing `common.mustCall()` wrapper. - Make small stylistic changes (e.g., remove unnecessary line breaks in comments) to make it visually consistent with the http test. * Use arrow functions. PR-URL: #13935Fixes: #13588 Refs: #13802 Refs: #13625 Refs: #13822 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 3b3d47c commit 346f199

2 files changed

Lines changed: 53 additions & 60 deletions

File tree

‎test/parallel/test-http-set-timeout-server.js‎

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ function run() {
2121
}
2222

2323
test(functionserverTimeout(cb){
24-
constserver=http.createServer(common.mustCall(function(req,res){
24+
constserver=http.createServer(common.mustCall((req,res)=>{
2525
// just do nothing, we should get a timeout event.
2626
}));
27-
server.listen(common.mustCall(function(){
28-
consts=server.setTimeout(50,common.mustCall(function(socket){
27+
server.listen(common.mustCall(()=>{
28+
consts=server.setTimeout(50,common.mustCall((socket)=>{
2929
socket.destroy();
3030
server.close();
3131
cb();
@@ -38,16 +38,16 @@ test(function serverTimeout(cb) {
3838
});
3939

4040
test(functionserverRequestTimeout(cb){
41-
constserver=http.createServer(common.mustCall(function(req,res){
41+
constserver=http.createServer(common.mustCall((req,res)=>{
4242
// just do nothing, we should get a timeout event.
43-
consts=req.setTimeout(50,common.mustCall(function(socket){
43+
consts=req.setTimeout(50,common.mustCall((socket)=>{
4444
socket.destroy();
4545
server.close();
4646
cb();
4747
}));
4848
assert.ok(sinstanceofhttp.IncomingMessage);
4949
}));
50-
server.listen(common.mustCall(function(){
50+
server.listen(common.mustCall(()=>{
5151
constreq=http.request({
5252
port: server.address().port,
5353
method: 'POST'
@@ -59,35 +59,35 @@ test(function serverRequestTimeout(cb) {
5959
});
6060

6161
test(functionserverResponseTimeout(cb){
62-
constserver=http.createServer(common.mustCall(function(req,res){
62+
constserver=http.createServer(common.mustCall((req,res)=>{
6363
// just do nothing, we should get a timeout event.
64-
consts=res.setTimeout(50,common.mustCall(function(socket){
64+
consts=res.setTimeout(50,common.mustCall((socket)=>{
6565
socket.destroy();
6666
server.close();
6767
cb();
6868
}));
6969
assert.ok(sinstanceofhttp.OutgoingMessage);
7070
}));
71-
server.listen(common.mustCall(function(){
71+
server.listen(common.mustCall(()=>{
7272
http.get({
7373
port: server.address().port
7474
}).on('error',common.mustCall());
7575
}));
7676
});
7777

7878
test(functionserverRequestNotTimeoutAfterEnd(cb){
79-
constserver=http.createServer(common.mustCall(function(req,res){
79+
constserver=http.createServer(common.mustCall((req,res)=>{
8080
// just do nothing, we should get a timeout event.
8181
consts=req.setTimeout(50,common.mustNotCall());
8282
assert.ok(sinstanceofhttp.IncomingMessage);
8383
res.on('timeout',common.mustCall());
8484
}));
85-
server.on('timeout',common.mustCall(function(socket){
85+
server.on('timeout',common.mustCall((socket)=>{
8686
socket.destroy();
8787
server.close();
8888
cb();
8989
}));
90-
server.listen(common.mustCall(function(){
90+
server.listen(common.mustCall(()=>{
9191
http.get({
9292
port: server.address().port
9393
}).on('error',common.mustCall());
@@ -97,31 +97,31 @@ test(function serverRequestNotTimeoutAfterEnd(cb) {
9797
test(functionserverResponseTimeoutWithPipeline(cb){
9898
letcaughtTimeout='';
9999
letsecReceived=false;
100-
process.on('exit',function(){
100+
process.on('exit',()=>{
101101
assert.strictEqual(caughtTimeout,'/2');
102102
});
103-
constserver=http.createServer(function(req,res){
103+
constserver=http.createServer((req,res)=>{
104104
if(req.url==='/2')
105105
secReceived=true;
106-
consts=res.setTimeout(50,function(){
106+
consts=res.setTimeout(50,()=>{
107107
caughtTimeout+=req.url;
108108
});
109109
assert.ok(sinstanceofhttp.OutgoingMessage);
110110
if(req.url==='/1')res.end();
111111
});
112-
server.on('timeout',common.mustCall(function(socket){
112+
server.on('timeout',common.mustCall((socket)=>{
113113
if(secReceived){
114114
socket.destroy();
115115
server.close();
116116
cb();
117117
}
118118
}));
119-
server.listen(common.mustCall(function(){
119+
server.listen(common.mustCall(()=>{
120120
constoptions={
121121
port: server.address().port,
122122
allowHalfOpen: true,
123123
};
124-
constc=net.connect(options,function(){
124+
constc=net.connect(options,()=>{
125125
c.write('GET /1 HTTP/1.1\r\nHost: localhost\r\n\r\n');
126126
c.write('GET /2 HTTP/1.1\r\nHost: localhost\r\n\r\n');
127127
c.write('GET /3 HTTP/1.1\r\nHost: localhost\r\n\r\n');
@@ -130,23 +130,23 @@ test(function serverResponseTimeoutWithPipeline(cb) {
130130
});
131131

132132
test(functionidleTimeout(cb){
133-
constserver=http.createServer(common.mustCall(function(req,res){
133+
constserver=http.createServer(common.mustCall((req,res)=>{
134134
req.on('timeout',common.mustNotCall());
135135
res.on('timeout',common.mustNotCall());
136136
res.end();
137137
}));
138-
consts=server.setTimeout(50,common.mustCall(function(socket){
138+
consts=server.setTimeout(50,common.mustCall((socket)=>{
139139
socket.destroy();
140140
server.close();
141141
cb();
142142
}));
143143
assert.ok(sinstanceofhttp.Server);
144-
server.listen(common.mustCall(function(){
144+
server.listen(common.mustCall(()=>{
145145
constoptions={
146146
port: server.address().port,
147147
allowHalfOpen: true,
148148
};
149-
constc=net.connect(options,function(){
149+
constc=net.connect(options,()=>{
150150
c.write('GET /1 HTTP/1.1\r\nHost: localhost\r\n\r\n');
151151
// Keep-Alive
152152
});

‎test/sequential/test-https-set-timeout-server.js‎

Lines changed: 31 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,24 @@ const serverOptions = {
2323
functiontest(fn){
2424
if(!tests.length)
2525
process.nextTick(run);
26-
tests.push(fn);
26+
tests.push(common.mustCall(fn));
2727
}
2828

2929
functionrun(){
3030
constfn=tests.shift();
3131
if(fn){
32-
console.log('# %s',fn.name);
3332
fn(run);
34-
}else{
35-
console.log('ok');
3633
}
3734
}
3835

3936
test(functionserverTimeout(cb){
4037
constserver=https.createServer(
4138
serverOptions,
42-
common.mustCall(function(req,res){
43-
// just do nothing, we should get a
44-
// timeout event.
39+
common.mustCall((req,res)=>{
40+
// just do nothing, we should get a timeout event.
4541
}));
46-
server.listen(common.mustCall(function(){
47-
consts=server.setTimeout(50,common.mustCall(function(socket){
42+
server.listen(common.mustCall(()=>{
43+
consts=server.setTimeout(50,common.mustCall((socket)=>{
4844
socket.destroy();
4945
server.close();
5046
cb();
@@ -60,19 +56,16 @@ test(function serverTimeout(cb) {
6056
test(functionserverRequestTimeout(cb){
6157
constserver=https.createServer(
6258
serverOptions,
63-
common.mustCall(function(req,res){
64-
// just do nothing, we should get a
65-
// timeout event.
66-
consts=req.setTimeout(
67-
50,
68-
common.mustCall(function(socket){
69-
socket.destroy();
70-
server.close();
71-
cb();
72-
}));
59+
common.mustCall((req,res)=>{
60+
// just do nothing, we should get a timeout event.
61+
consts=req.setTimeout(50,common.mustCall((socket)=>{
62+
socket.destroy();
63+
server.close();
64+
cb();
65+
}));
7366
assert.ok(sinstanceofhttp.IncomingMessage);
7467
}));
75-
server.listen(common.mustCall(function(){
68+
server.listen(common.mustCall(()=>{
7669
constreq=https.request({
7770
port: server.address().port,
7871
method: 'POST',
@@ -87,16 +80,16 @@ test(function serverRequestTimeout(cb) {
8780
test(functionserverResponseTimeout(cb){
8881
constserver=https.createServer(
8982
serverOptions,
90-
common.mustCall(function(req,res){
83+
common.mustCall((req,res)=>{
9184
// just do nothing, we should get a timeout event.
92-
consts=res.setTimeout(50,common.mustCall(function(socket){
85+
consts=res.setTimeout(50,common.mustCall((socket)=>{
9386
socket.destroy();
9487
server.close();
9588
cb();
9689
}));
9790
assert.ok(sinstanceofhttp.OutgoingMessage);
9891
}));
99-
server.listen(common.mustCall(function(){
92+
server.listen(common.mustCall(()=>{
10093
https.get({
10194
port: server.address().port,
10295
rejectUnauthorized: false
@@ -107,18 +100,18 @@ test(function serverResponseTimeout(cb) {
107100
test(functionserverRequestNotTimeoutAfterEnd(cb){
108101
constserver=https.createServer(
109102
serverOptions,
110-
common.mustCall(function(req,res){
103+
common.mustCall((req,res)=>{
111104
// just do nothing, we should get a timeout event.
112105
consts=req.setTimeout(50,common.mustNotCall());
113106
assert.ok(sinstanceofhttp.IncomingMessage);
114107
res.on('timeout',common.mustCall());
115108
}));
116-
server.on('timeout',common.mustCall(function(socket){
109+
server.on('timeout',common.mustCall((socket)=>{
117110
socket.destroy();
118111
server.close();
119112
cb();
120113
}));
121-
server.listen(common.mustCall(function(){
114+
server.listen(common.mustCall(()=>{
122115
https.get({
123116
port: server.address().port,
124117
rejectUnauthorized: false
@@ -129,32 +122,32 @@ test(function serverRequestNotTimeoutAfterEnd(cb) {
129122
test(functionserverResponseTimeoutWithPipeline(cb){
130123
letcaughtTimeout='';
131124
letsecReceived=false;
132-
process.on('exit',function(){
125+
process.on('exit',()=>{
133126
assert.strictEqual(caughtTimeout,'/2');
134127
});
135-
constserver=https.createServer(serverOptions,function(req,res){
128+
constserver=https.createServer(serverOptions,(req,res)=>{
136129
if(req.url==='/2')
137130
secReceived=true;
138-
consts=res.setTimeout(50,function(){
131+
consts=res.setTimeout(50,()=>{
139132
caughtTimeout+=req.url;
140133
});
141134
assert.ok(sinstanceofhttp.OutgoingMessage);
142135
if(req.url==='/1')res.end();
143136
});
144-
server.on('timeout',function(socket){
137+
server.on('timeout',common.mustCall((socket)=>{
145138
if(secReceived){
146139
socket.destroy();
147140
server.close();
148141
cb();
149142
}
150-
});
151-
server.listen(common.mustCall(function(){
143+
}));
144+
server.listen(common.mustCall(()=>{
152145
constoptions={
153146
port: server.address().port,
154147
allowHalfOpen: true,
155148
rejectUnauthorized: false
156149
};
157-
constc=tls.connect(options,function(){
150+
constc=tls.connect(options,()=>{
158151
c.write('GET /1 HTTP/1.1\r\nHost: localhost\r\n\r\n');
159152
c.write('GET /2 HTTP/1.1\r\nHost: localhost\r\n\r\n');
160153
c.write('GET /3 HTTP/1.1\r\nHost: localhost\r\n\r\n');
@@ -165,25 +158,25 @@ test(function serverResponseTimeoutWithPipeline(cb) {
165158
test(functionidleTimeout(cb){
166159
constserver=https.createServer(
167160
serverOptions,
168-
common.mustCall(function(req,res){
161+
common.mustCall((req,res)=>{
169162
req.on('timeout',common.mustNotCall());
170163
res.on('timeout',common.mustNotCall());
171164
res.end();
172165
}));
173-
consts=server.setTimeout(50,common.mustCall(function(socket){
166+
consts=server.setTimeout(50,common.mustCall((socket)=>{
174167
socket.destroy();
175168
server.close();
176169
cb();
177170
}));
178171
assert.ok(sinstanceofhttps.Server);
179-
server.listen(common.mustCall(function(){
172+
server.listen(common.mustCall(()=>{
180173
constoptions={
181174
port: server.address().port,
182175
allowHalfOpen: true,
183176
rejectUnauthorized: false
184177
};
185-
tls.connect(options,function(){
186-
this.write('GET /1 HTTP/1.1\r\nHost: localhost\r\n\r\n');
178+
constc=tls.connect(options,()=>{
179+
c.write('GET /1 HTTP/1.1\r\nHost: localhost\r\n\r\n');
187180
// Keep-Alive
188181
});
189182
}));

0 commit comments

Comments
 (0)