From 40952422cddc191274ec3dc67e90f6a081a2b534 Mon Sep 17 00:00:00 2001 From: Mandeep Singh Date: Sun, 26 Nov 2017 22:27:00 +0530 Subject: [PATCH] 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 Reviewed-By: Jon Moss Reviewed-By: Anna Henningsen --- test/parallel/test-http-client-agent.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/test/parallel/test-http-client-agent.js b/test/parallel/test-http-client-agent.js index f2d1b612b5af82..3ae906f09c92ae 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();