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: simplify test-gc-{http-client,net}-* #42782

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
35 changes: 21 additions & 14 deletions test/parallel/test-gc-http-client-connaborted.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,27 @@

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

const http = require('http');
const todo = 500;
const os = require('os');

const cpus = os.cpus().length;
let createClients = true;
let done = 0;
let count = 0;
let countGC = 0;

console.log(`We should do ${todo} requests`);

function serverHandler(req, res) {
res.connection.destroy();
}

const server = http.createServer(serverHandler);
server.listen(0, common.mustCall(() => {
for (let i = 0; i < 10; i++)
getall();
for (let i = 0; i < cpus; i++)
getAll();
}));

function getall() {
if (count >= todo)
function getAll() {
if (!createClients)
return;

const req = http.get({
Expand All @@ -37,7 +37,7 @@ function getall() {
count++;
onGC(req, { ongc });

setImmediate(getall);
setImmediate(getAll);
}

function cb(res) {
Expand All @@ -48,11 +48,18 @@ function ongc() {
countGC++;
}

setInterval(status, 100).unref();
setImmediate(status);

function status() {
global.gc();
console.log('Done: %d/%d', done, todo);
console.log('Collected: %d/%d', countGC, count);
if (countGC === todo) server.close();
if (done > 0) {
createClients = false;
global.gc();
console.log(`done/collected/total: ${done}/${countGC}/${count}`);
if (countGC === count) {
server.close();
return;
}
}

setImmediate(status);
}
41 changes: 23 additions & 18 deletions test/parallel/test-gc-http-client-timeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

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 @@ -14,19 +16,17 @@ function serverHandler(req, res) {
}, 100);
}

const http = require('http');
const todo = 300;
const cpus = os.cpus().length;
let createClients = true;
let done = 0;
let count = 0;
let countGC = 0;

console.log(`We should do ${todo} requests`);

const server = http.createServer(serverHandler);
server.listen(0, common.mustCall(getall));
server.listen(0, common.mustCall(getAll));

function getall() {
if (count >= todo)
function getAll() {
if (!createClients)
return;

const req = http.get({
Expand All @@ -35,18 +35,16 @@ function getall() {
port: server.address().port
}, cb);

req.setTimeout(10, function() {
console.log('timeout (expected)');
});
req.setTimeout(10, common.mustCall());

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

setImmediate(getall);
setImmediate(getAll);
}

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

function cb(res) {
res.resume();
Expand All @@ -57,11 +55,18 @@ function ongc() {
countGC++;
}

setInterval(status, 100).unref();
setImmediate(status);

function status() {
global.gc();
console.log('Done: %d/%d', done, todo);
console.log('Collected: %d/%d', countGC, count);
if (countGC === todo) server.close();
if (done > 0) {
createClients = false;
global.gc();
console.log(`done/collected/total: ${done}/${countGC}/${count}`);
if (countGC === count) {
server.close();
return;
}
}

setImmediate(status);
}
39 changes: 23 additions & 16 deletions test/parallel/test-gc-net-timeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

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

function serverHandler(sock) {
sock.setTimeout(120000);
Expand All @@ -23,20 +26,17 @@ function serverHandler(sock) {
}, 100);
}

const net = require('net');
const assert = require('assert');
const todo = 500;
const cpus = os.cpus().length;
let createClients = true;
let done = 0;
let count = 0;
let countGC = 0;

console.log(`We should do ${todo} requests`);

const server = net.createServer(serverHandler);
server.listen(0, getall);
server.listen(0, getAll);

function getall() {
if (count >= todo)
function getAll() {
if (!createClients)
return;

const req = net.connect(server.address().port);
Expand All @@ -49,21 +49,28 @@ function getall() {
count++;
onGC(req, { ongc });

setImmediate(getall);
setImmediate(getAll);
}

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

function ongc() {
countGC++;
}

setInterval(status, 100).unref();
setImmediate(status);

function status() {
global.gc();
console.log('Done: %d/%d', done, todo);
console.log('Collected: %d/%d', countGC, count);
if (countGC === todo) server.close();
if (done > 0) {
createClients = false;
global.gc();
console.log(`done/collected/total: ${done}/${countGC}/${count}`);
if (countGC === count) {
server.close();
return;
}
}

setImmediate(status);
}