Skip to content

Commit

Permalink
test: harden test-gc-http-client-timeout
Browse files Browse the repository at this point in the history
* decrease number of requests 500 -> 300
* extract 'cb' to a file-local function

This should make test more reliable and less resource intensive.

PR-URL: #23184
Refs: #23066
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
lundibundi authored and targos committed Oct 5, 2018
1 parent 49b0ec4 commit 9352d9d
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions test/sequential/test-gc-http-client-timeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// just like test-gc-http-client.js,
// but with a timeout set

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

function serverHandler(req, res) {
Expand All @@ -15,46 +15,44 @@ function serverHandler(req, res) {
}

const http = require('http');
const todo = 550;
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(getall));

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

(function() {
function cb(res) {
res.resume();
done += 1;
}
const req = http.get({
hostname: 'localhost',
pathname: '/',
port: server.address().port
}, cb);

const req = http.get({
hostname: 'localhost',
pathname: '/',
port: server.address().port
}, cb);
req.setTimeout(10, function() {
console.log('timeout (expected)');
});

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

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

setImmediate(getall);
}

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

function cb(res) {
res.resume();
done += 1;
}

function ongc() {
countGC++;
}
Expand Down

0 comments on commit 9352d9d

Please sign in to comment.