Skip to content

Commit 86a7fb0

Browse files
nicksia-vgwruyadorno
authored andcommitted
test: deflake gc-http-client tests by restricting number of requests
sequential/test-gc-http-client tests were sometimes failing due to a non-deterministic number of requests being created, causing the test to fail on some systems with a "ECONNRESET" error caused by too many concurrent connections Fixes: #43638 PR-URL: #44146 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: theanarkh <theratliter@gmail.com> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
1 parent e17117d commit 86a7fb0

3 files changed

Lines changed: 32 additions & 19 deletions

File tree

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

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ function serverHandler(req, res) {
1515
}
1616

1717
consthttp=require('http');
18+
constnumRequests=36;
1819
letcreateClients=true;
1920
letdone=0;
2021
letcount=0;
@@ -23,22 +24,26 @@ let countGC = 0;
2324
constserver=http.createServer(serverHandler);
2425
server.listen(0,common.mustCall(()=>{
2526
for(leti=0;i<cpus;i++)
26-
getAll();
27+
getAll(numRequests);
2728
}));
2829

29-
functiongetAll(){
30-
if(createClients){
31-
constreq=http.get({
32-
hostname: 'localhost',
33-
pathname: '/',
34-
port: server.address().port
35-
},cb).on('error',onerror);
30+
functiongetAll(requestsRemaining){
31+
if(!createClients)
32+
return;
3633

37-
count++;
38-
onGC(req,{ ongc });
34+
if(requestsRemaining<=0)
35+
return;
3936

40-
setImmediate(getAll);
41-
}
37+
constreq=http.get({
38+
hostname: 'localhost',
39+
pathname: '/',
40+
port: server.address().port
41+
},cb).on('error',onerror);
42+
43+
count++;
44+
onGC(req,{ ongc });
45+
46+
setImmediate(getAll,requestsRemaining-1);
4247
}
4348

4449
functioncb(res){

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,22 @@ function serverHandler(req, res) {
1717
}
1818

1919
constcpus=os.cpus().length;
20+
constnumRequests=36;
2021
letcreateClients=true;
2122
letdone=0;
2223
letcount=0;
2324
letcountGC=0;
2425

2526
constserver=http.createServer(serverHandler);
26-
server.listen(0,common.mustCall(getAll));
27+
server.listen(0,common.mustCall(()=>getAll(numRequests)));
2728

28-
functiongetAll(){
29+
functiongetAll(requestsRemaining){
2930
if(!createClients)
3031
return;
3132

33+
if(requestsRemaining<=0)
34+
return;
35+
3236
constreq=http.get({
3337
hostname: 'localhost',
3438
pathname: '/',
@@ -40,11 +44,11 @@ function getAll() {
4044
count++;
4145
onGC(req,{ ongc });
4246

43-
setImmediate(getAll);
47+
setImmediate(getAll,requestsRemaining-1);
4448
}
4549

4650
for(leti=0;i<cpus;i++)
47-
getAll();
51+
getAll(numRequests);
4852

4953
functioncb(res){
5054
res.resume();

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ function serverHandler(req, res) {
1313
}
1414

1515
consthttp=require('http');
16+
constnumRequests=36;
1617
letcreateClients=true;
1718
letdone=0;
1819
letcount=0;
@@ -21,13 +22,16 @@ let countGC = 0;
2122
constserver=http.createServer(serverHandler);
2223
server.listen(0,common.mustCall(()=>{
2324
for(leti=0;i<cpus;i++)
24-
getAll();
25+
getAll(numRequests);
2526
}));
2627

27-
functiongetAll(){
28+
functiongetAll(requestsRemaining){
2829
if(!createClients)
2930
return;
3031

32+
if(requestsRemaining<=0)
33+
return;
34+
3135
constreq=http.get({
3236
hostname: 'localhost',
3337
pathname: '/',
@@ -37,7 +41,7 @@ function getAll() {
3741
count++;
3842
onGC(req,{ ongc });
3943

40-
setImmediate(getAll);
44+
setImmediate(getAll,requestsRemaining-1);
4145
}
4246

4347
functioncb(res){

0 commit comments

Comments
 (0)