From bb780d2d84c72c35e396c06e5373f7806d60f87a Mon Sep 17 00:00:00 2001 From: Federico Kauffman Date: Thu, 7 Dec 2017 19:20:54 -0300 Subject: [PATCH] test: use Countdown in http-agent test PR-URL: https://github.com/nodejs/node/pull/17537 Reviewed-By: Anatoli Papirovski --- test/parallel/test-http-agent.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/test/parallel/test-http-agent.js b/test/parallel/test-http-agent.js index 106f641db72a18..6dc7f75ce0bc05 100644 --- a/test/parallel/test-http-agent.js +++ b/test/parallel/test-http-agent.js @@ -21,6 +21,7 @@ 'use strict'; const common = require('../common'); +const Countdown = require('../common/countdown'); const assert = require('assert'); const http = require('http'); common.crashOnUnhandledRejection(); @@ -33,14 +34,17 @@ const server = http.Server(common.mustCall(function(req, res) { }, (N * M))); // N * M = good requests (the errors will not be counted) function makeRequests(outCount, inCount, shouldFail) { - let responseCount = outCount * inCount; + const countdown = new Countdown( + outCount * inCount, + common.mustCall(() => server.close()) + ); let onRequest = common.mustNotCall(); // Temporary const p = new Promise((resolve) => { onRequest = common.mustCall((res) => { - if (--responseCount === 0) { - server.close(); + if (countdown.dec() === 0) { resolve(); } + if (!shouldFail) res.resume(); }, outCount * inCount);