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: Update test-http-client-agent to use countdown timer
Fixes: #17169
  • Loading branch information
daxlab committed Nov 26, 2017
commit a01d39cb5ce35c0154bf30d7326461ae03ba75d2
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