diff options
author | Mandeep Singh <mandeep25894@gmail.com> | 2017-11-26 22:27:00 +0530 |
---|---|---|
committer | Gibson Fahnestock <gibfahn@gmail.com> | 2017-12-20 01:59:26 +0000 |
commit | 6137afad8cf3db758593e8c72d0f8060cfccc13e (patch) | |
tree | 9edd00d81587746f6cdd56c2b7d3a17d167bd7ff /test/parallel/test-http-client-agent.js | |
parent | 63a35133f90902dfb1175dd55d5c13e6b6e48a82 (diff) | |
download | node-new-6137afad8cf3db758593e8c72d0f8060cfccc13e.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.js | 16 |
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(); |