mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
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: https://github.com/nodejs/node/issues/43638 PR-URL: https://github.com/nodejs/node/pull/44146 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: theanarkh <theratliter@gmail.com> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
This commit is contained in:
@@ -15,6 +15,7 @@ function serverHandler(req, res) {
|
||||
}
|
||||
|
||||
const http = require('http');
|
||||
const numRequests = 36;
|
||||
let createClients = true;
|
||||
let done = 0;
|
||||
let count = 0;
|
||||
@@ -23,22 +24,26 @@ let countGC = 0;
|
||||
const server = http.createServer(serverHandler);
|
||||
server.listen(0, common.mustCall(() => {
|
||||
for (let i = 0; i < cpus; i++)
|
||||
getAll();
|
||||
getAll(numRequests);
|
||||
}));
|
||||
|
||||
function getAll() {
|
||||
if (createClients) {
|
||||
const req = http.get({
|
||||
hostname: 'localhost',
|
||||
pathname: '/',
|
||||
port: server.address().port
|
||||
}, cb).on('error', onerror);
|
||||
function getAll(requestsRemaining) {
|
||||
if (!createClients)
|
||||
return;
|
||||
|
||||
count++;
|
||||
onGC(req, { ongc });
|
||||
if (requestsRemaining <= 0)
|
||||
return;
|
||||
|
||||
setImmediate(getAll);
|
||||
}
|
||||
const req = http.get({
|
||||
hostname: 'localhost',
|
||||
pathname: '/',
|
||||
port: server.address().port
|
||||
}, cb).on('error', onerror);
|
||||
|
||||
count++;
|
||||
onGC(req, { ongc });
|
||||
|
||||
setImmediate(getAll, requestsRemaining - 1);
|
||||
}
|
||||
|
||||
function cb(res) {
|
||||
|
||||
@@ -17,18 +17,22 @@ function serverHandler(req, res) {
|
||||
}
|
||||
|
||||
const cpus = os.cpus().length;
|
||||
const numRequests = 36;
|
||||
let createClients = true;
|
||||
let done = 0;
|
||||
let count = 0;
|
||||
let countGC = 0;
|
||||
|
||||
const server = http.createServer(serverHandler);
|
||||
server.listen(0, common.mustCall(getAll));
|
||||
server.listen(0, common.mustCall(() => getAll(numRequests)));
|
||||
|
||||
function getAll() {
|
||||
function getAll(requestsRemaining) {
|
||||
if (!createClients)
|
||||
return;
|
||||
|
||||
if (requestsRemaining <= 0)
|
||||
return;
|
||||
|
||||
const req = http.get({
|
||||
hostname: 'localhost',
|
||||
pathname: '/',
|
||||
@@ -40,11 +44,11 @@ function getAll() {
|
||||
count++;
|
||||
onGC(req, { ongc });
|
||||
|
||||
setImmediate(getAll);
|
||||
setImmediate(getAll, requestsRemaining - 1);
|
||||
}
|
||||
|
||||
for (let i = 0; i < cpus; i++)
|
||||
getAll();
|
||||
getAll(numRequests);
|
||||
|
||||
function cb(res) {
|
||||
res.resume();
|
||||
|
||||
@@ -13,6 +13,7 @@ function serverHandler(req, res) {
|
||||
}
|
||||
|
||||
const http = require('http');
|
||||
const numRequests = 36;
|
||||
let createClients = true;
|
||||
let done = 0;
|
||||
let count = 0;
|
||||
@@ -21,13 +22,16 @@ let countGC = 0;
|
||||
const server = http.createServer(serverHandler);
|
||||
server.listen(0, common.mustCall(() => {
|
||||
for (let i = 0; i < cpus; i++)
|
||||
getAll();
|
||||
getAll(numRequests);
|
||||
}));
|
||||
|
||||
function getAll() {
|
||||
function getAll(requestsRemaining) {
|
||||
if (!createClients)
|
||||
return;
|
||||
|
||||
if (requestsRemaining <= 0)
|
||||
return;
|
||||
|
||||
const req = http.get({
|
||||
hostname: 'localhost',
|
||||
pathname: '/',
|
||||
@@ -37,7 +41,7 @@ function getAll() {
|
||||
count++;
|
||||
onGC(req, { ongc });
|
||||
|
||||
setImmediate(getAll);
|
||||
setImmediate(getAll, requestsRemaining - 1);
|
||||
}
|
||||
|
||||
function cb(res) {
|
||||
|
||||
Reference in New Issue
Block a user