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
  • Loading branch information
daxlab committed Nov 26, 2017
1 parent 9de15de commit a01d39c
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 a01d39c

Please sign in to comment.