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 <jasnell@gmail.com>
Reviewed-By: Jon Moss <me@jonathanmoss.me>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
  • Loading branch information
daxlab authored and gibfahn committed Dec 20, 2017
1 parent 63a3513 commit 6137afa
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions test/parallel/test-http-client-agent.js
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 6137afa

Please sign in to comment.