Skip to content
Closed
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
test: improve test-gc-http-client-connaborted
* refactor out usage of 'function' for scoping
* wait till server is up to start firing requests
  • Loading branch information
lundibundi committed Oct 8, 2018
commit 67771e972cbba64186821779d917503675330836
40 changes: 19 additions & 21 deletions test/sequential/test-gc-http-client-connaborted.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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++;
Expand Down