From 85e6271995e64be992caaae5867b669357568913 Mon Sep 17 00:00:00 2001 From: Mithun Sasidharan Date: Sun, 3 Dec 2017 13:42:02 +0530 Subject: [PATCH] test: use Countdown in http test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/17436 Reviewed-By: Anatoli Papirovski Reviewed-By: Jon Moss Reviewed-By: Tobias Nießen Reviewed-By: Luigi Pinca --- .../test-http-response-multi-content-length.js | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/test/parallel/test-http-response-multi-content-length.js b/test/parallel/test-http-response-multi-content-length.js index 14015475ca702d..b2d28b7a9bcec1 100644 --- a/test/parallel/test-http-response-multi-content-length.js +++ b/test/parallel/test-http-response-multi-content-length.js @@ -3,6 +3,7 @@ const common = require('../common'); const http = require('http'); const assert = require('assert'); +const Countdown = require('../common/countdown'); const MAX_COUNT = 2; @@ -24,7 +25,7 @@ const server = http.createServer((req, res) => { res.end('ok'); }); -let count = 0; +const countdown = new Countdown(MAX_COUNT, () => server.close()); server.listen(0, common.mustCall(() => { for (let n = 1; n <= MAX_COUNT; n++) { @@ -40,13 +41,7 @@ server.listen(0, common.mustCall(() => { ).on('error', common.mustCall((err) => { assert(/^Parse Error/.test(err.message)); assert.strictEqual(err.code, 'HPE_UNEXPECTED_CONTENT_LENGTH'); - count++; - if (count === MAX_COUNT) - server.close(); + countdown.dec(); })); } })); - -process.on('exit', () => { - assert.strictEqual(count, MAX_COUNT); -});