Skip to content
Permalink
Browse files

test: improve test-gc-http-client-connaborted

* refactor out usage of 'function' for scoping
* wait till server is up to start firing requests

PR-URL: #23193
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
  • Loading branch information
lundibundi authored and jasnell committed Oct 1, 2018
1 parent b61bbbb commit 91bad826387cb348fa9b6d6f72fa0685a2c333bf
Showing with 19 additions and 21 deletions.
  1. +19 −21 test/sequential/test-gc-http-client-connaborted.js
@@ -3,13 +3,9 @@
// just like test-gc-http-client.js,
// but aborting every connection that comes in.

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

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

const http = require('http');
const todo = 500;
let done = 0;
@@ -18,33 +14,35 @@ 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, getall);
server.listen(0, common.mustCall(() => {
for (let i = 0; i < 10; i++)
getall();
}));

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

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

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

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

setImmediate(getall);
}

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

function ongc() {
countGC++;

0 comments on commit 91bad82

Please sign in to comment.
You can’t perform that action at this time.