Skip to content

Commit

Permalink
test: harden test-gc-http-client
Browse files Browse the repository at this point in the history
This reduces the total number of requests from 500 to 300 and triggers
more requests in parallel. It also moves some function creation out
and waits with the first request until the server is listening.

PR-URL: #22373
Fixes: #22336
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
BridgeAR authored and joyeecheung committed Aug 20, 2018
1 parent 3479b1c commit 79642ae
Showing 1 changed file with 18 additions and 22 deletions.
40 changes: 18 additions & 22 deletions test/parallel/test-gc-http-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,44 +10,40 @@ function serverHandler(req, res) {
}

const http = require('http');
const todo = 500;
const todo = 300;
let done = 0;
let count = 0;
let countGC = 0;

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

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

server.listen(0, common.mustCall(() => {
for (let i = 0; i < 15; i++)
getall();
}));

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

(function() {
function cb(res) {
res.resume();
console.error('in cb');
done += 1;
res.on('end', global.gc);
}

const req = http.get({
hostname: 'localhost',
pathname: '/',
port: server.address().port
}, cb);
const req = http.get({
hostname: 'localhost',
pathname: '/',
port: server.address().port
}, cb);

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

setImmediate(getall);
}

for (let i = 0; i < 10; i++)
getall();
function cb(res) {
res.resume();
done += 1;
res.on('end', global.gc);
}

function ongc() {
countGC++;
Expand Down

0 comments on commit 79642ae

Please sign in to comment.