Skip to content

Commit

Permalink
test: refactor test-gc-http-client-timeout
Browse files Browse the repository at this point in the history
Due to server response delay, all possible requests are created anyway.
Instead of doing `36 * os.availableParallelism()` requests, use a fixed
number.

Refs: #48078 (comment)
  • Loading branch information
lpinca committed Jun 2, 2023
1 parent 2fca7ea commit e5521d2
Showing 1 changed file with 7 additions and 18 deletions.
25 changes: 7 additions & 18 deletions test/sequential/test-gc-http-client-timeout.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
'use strict';
// Flags: --expose-gc
// just like test-gc-http-client.js,
// but with a timeout set
// Like test-gc-http-client.js, but with a timeout set.

const common = require('../common');
const onGC = require('../common/ongc');
const http = require('http');
const os = require('os');

function serverHandler(req, res) {
setTimeout(function() {
Expand All @@ -16,20 +14,16 @@ function serverHandler(req, res) {
}, 100);
}

const cpus = os.availableParallelism();
const numRequests = 36;
let createClients = true;
const numRequests = 128;
let done = 0;
let count = 0;
let countGC = 0;

const server = http.createServer(serverHandler);
server.listen(0, common.mustCall(() => getAll(numRequests)));
server.listen(0, common.mustCall(() => {
getAll(numRequests);
}));

function getAll(requestsRemaining) {
if (!createClients)
return;

if (requestsRemaining <= 0)
return;

Expand All @@ -41,15 +35,11 @@ function getAll(requestsRemaining) {

req.setTimeout(10, common.mustCall());

count++;
onGC(req, { ongc });

setImmediate(getAll, requestsRemaining - 1);
}

for (let i = 0; i < cpus; i++)
getAll(numRequests);

function cb(res) {
res.resume();
done += 1;
Expand All @@ -63,10 +53,9 @@ setImmediate(status);

function status() {
if (done > 0) {
createClients = false;
global.gc();
console.log(`done/collected/total: ${done}/${countGC}/${count}`);
if (countGC === count) {
console.log(`done/collected/total: ${done}/${countGC}/${numRequests}`);
if (countGC === numRequests) {
server.close();
return;
}
Expand Down

0 comments on commit e5521d2

Please sign in to comment.