Skip to content

Commit

Permalink
test: improve test-gc-http-client-onerror
Browse files Browse the repository at this point in the history
* refactor out usage of 'function' for scoping
* inline runTest function

PR-URL: #23196
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
  • Loading branch information
lundibundi authored and jasnell committed Oct 17, 2018
1 parent 91bad82 commit 939a27e
Showing 1 changed file with 19 additions and 22 deletions.
41 changes: 19 additions & 22 deletions test/sequential/test-gc-http-client-onerror.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 an on('error') handler that does nothing.

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

function serverHandler(req, res) {
Expand All @@ -21,37 +21,34 @@ let countGC = 0;
console.log(`We should do ${todo} requests`);

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

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

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

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

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

setImmediate(getall);
}

function runTest() {
for (let i = 0; i < 10; i++)
getall();
function cb(res) {
res.resume();
done += 1;
}

function onerror(err) {
throw err;
}

function ongc() {
Expand Down

0 comments on commit 939a27e

Please sign in to comment.