Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: refactor test-gc-http-client-timeout #48292

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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