Skip to content

Commit 9352d9d

Browse files
lundibunditargos
authored andcommitted
test: harden test-gc-http-client-timeout
* decrease number of requests 500 -> 300 * extract 'cb' to a file-local function This should make test more reliable and less resource intensive. PR-URL: #23184 Refs: #23066 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 49b0ec4 commit 9352d9d

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

‎test/sequential/test-gc-http-client-timeout.js‎

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// just like test-gc-http-client.js,
44
// but with a timeout set
55

6-
require('../common');
6+
constcommon=require('../common');
77
constonGC=require('../common/ongc');
88

99
functionserverHandler(req,res){
@@ -15,46 +15,44 @@ function serverHandler(req, res){
1515
}
1616

1717
consthttp=require('http');
18-
consttodo=550;
18+
consttodo=300;
1919
letdone=0;
2020
letcount=0;
2121
letcountGC=0;
2222

2323
console.log(`We should do ${todo} requests`);
2424

2525
constserver=http.createServer(serverHandler);
26-
server.listen(0,getall);
26+
server.listen(0,common.mustCall(getall));
2727

2828
functiongetall(){
2929
if(count>=todo)
3030
return;
3131

32-
(function(){
33-
functioncb(res){
34-
res.resume();
35-
done+=1;
36-
}
32+
constreq=http.get({
33+
hostname: 'localhost',
34+
pathname: '/',
35+
port: server.address().port
36+
},cb);
3737

38-
constreq=http.get({
39-
hostname: 'localhost',
40-
pathname: '/',
41-
port: server.address().port
42-
},cb);
38+
req.setTimeout(10,function(){
39+
console.log('timeout (expected)');
40+
});
4341

44-
req.setTimeout(10,function(){
45-
console.log('timeout (expected)');
46-
});
47-
48-
count++;
49-
onGC(req,{ ongc });
50-
})();
42+
count++;
43+
onGC(req,{ ongc });
5144

5245
setImmediate(getall);
5346
}
5447

5548
for(leti=0;i<10;i++)
5649
getall();
5750

51+
functioncb(res){
52+
res.resume();
53+
done+=1;
54+
}
55+
5856
functionongc(){
5957
countGC++;
6058
}

0 commit comments

Comments
(0)