diff --git a/test/parallel/test-https-agent.js b/test/parallel/test-https-agent.js index 4b2f9e73a1cd79..986d3526520fe7 100644 --- a/test/parallel/test-https-agent.js +++ b/test/parallel/test-https-agent.js @@ -21,6 +21,7 @@ 'use strict'; const common = require('../common'); +const Countdown = require('../common/countdown'); if (!common.hasCrypto) common.skip('missing crypto'); @@ -40,11 +41,14 @@ const server = https.Server(options, function(req, res) { res.end('hello world\n'); }); - let responses = 0; const N = 4; const M = 4; +const cd = new Countdown(N * M, () => { + server.close(); +}); + server.listen(0, function() { for (let i = 0; i < N; i++) { @@ -57,7 +61,8 @@ server.listen(0, function() { }, function(res) { res.resume(); assert.strictEqual(res.statusCode, 200); - if (++responses === N * M) server.close(); + ++responses; + cd.dec(); }).on('error', function(e) { throw e; });