Skip to content

Commit

Permalink
test: Update test-http-client-agent to use countdown timer
Browse files Browse the repository at this point in the history
PR-URL: #17325
Refs: #17169
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Jon Moss <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
  • Loading branch information
daxlab authored and gibfahn committed Dec 19, 2017
1 parent 2d7e03f commit 4f0cdae
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions test/parallel/test-http-client-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
const common = require('../common');
const assert = require('assert');
const http = require('http');
const Countdown = require('../common/countdown');

let name;
const max = 3;
let count = 0;

const server = http.Server(common.mustCall((req, res) => {
if (req.url === '/0') {
Expand All @@ -45,21 +45,23 @@ server.listen(0, common.mustCall(() => {
request(i);
}));

const countdown = new Countdown(max, () => {
assert(!http.globalAgent.sockets.hasOwnProperty(name));
assert(!http.globalAgent.requests.hasOwnProperty(name));
server.close();
});

function request(i) {
const req = http.get({
port: server.address().port,
path: `/${i}`
}, function(res) {
const socket = req.socket;
socket.on('close', common.mustCall(() => {
++count;
if (count < max) {
countdown.dec();
if (countdown.remaining > 0) {
assert.strictEqual(http.globalAgent.sockets[name].includes(socket),
false);
} else {
assert(!http.globalAgent.sockets.hasOwnProperty(name));
assert(!http.globalAgent.requests.hasOwnProperty(name));
server.close();
}
}));
res.resume();
Expand Down

0 comments on commit 4f0cdae

Please sign in to comment.