summaryrefslogtreecommitdiff
path: root/test/parallel/test-http-client-agent.js
diff options
context:
space:
mode:
authorMandeep Singh <mandeep25894@gmail.com>2017-11-26 22:27:00 +0530
committerAnna Henningsen <anna@addaleax.net>2017-11-28 02:40:31 +0100
commit3996da6d266a444f2fc8576d57f1ed4ef63e532c (patch)
tree4c6e1c2a5b0f3e8833b513b74540f59a5a116027 /test/parallel/test-http-client-agent.js
parentaec9149c1ea64ffc045eb99ad5c3b8b585fc5aff (diff)
downloadnode-new-3996da6d266a444f2fc8576d57f1ed4ef63e532c.tar.gz
test: Update test-http-client-agent to use countdown timer
PR-URL: https://github.com/nodejs/node/pull/17325 Refs: https://github.com/nodejs/node/issues/17169 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jon Moss <me@jonathanmoss.me> Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'test/parallel/test-http-client-agent.js')
-rw-r--r--test/parallel/test-http-client-agent.js16
1 files changed, 9 insertions, 7 deletions
diff --git a/test/parallel/test-http-client-agent.js b/test/parallel/test-http-client-agent.js
index f2d1b612b5..3ae906f09c 100644
--- a/test/parallel/test-http-client-agent.js
+++ b/test/parallel/test-http-client-agent.js
@@ -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') {
@@ -45,6 +45,12 @@ 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,
@@ -52,14 +58,10 @@ function request(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();