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

File tree

3 files changed

+32
-19
lines changed

3 files changed

+32
-19
lines changed

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

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

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

29-
function getAll() {
30-
if (createClients) {
31-
const req = http.get({
32-
hostname: 'localhost',
33-
pathname: '/',
34-
port: server.address().port
35-
}, cb).on('error', onerror);
30+
function getAll(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+
const req = 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
function cb(res) {

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

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

1919
const cpus = os.cpus().length;
20+
const numRequests = 36;
2021
let createClients = true;
2122
let done = 0;
2223
let count = 0;
2324
let countGC = 0;
2425

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

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

33+
if (requestsRemaining <= 0)
34+
return;
35+
3236
const req = 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 (let i = 0; i < cpus; i++)
47-
getAll();
51+
getAll(numRequests);
4852

4953
function cb(res) {
5054
res.resume();

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

+7-3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ function serverHandler(req, res) {
1313
}
1414

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

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

32+
if (requestsRemaining <= 0)
33+
return;
34+
3135
const req = 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
function cb(res) {

0 commit comments

Comments
 (0)