Permalink
Browse files

test: Update test-http-client-agent to use countdown timer

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 Nov 26, 2017
1 parent 3eab248 commit 956198f30d3d8dc48adb975b44d59f494d7a3ef3
Showing with 9 additions and 7 deletions.
  1. +9 −7 test/parallel/test-http-client-agent.js
@@ -2,10 +2,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') {
@@ -24,21 +24,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();

0 comments on commit 956198f

Please sign in to comment.