From 76f0039d472e236dfeac93c6951e0c5ec1986d29 Mon Sep 17 00:00:00 2001 From: Mithun Sasidharan Date: Mon, 27 Nov 2017 12:44:12 +0530 Subject: [PATCH] Updated `test-http-upgrade-client` to use countdown --- test/parallel/test-http-upgrade-client.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/parallel/test-http-upgrade-client.js b/test/parallel/test-http-upgrade-client.js index 3c56e5959fbd93..c637324a53d801 100644 --- a/test/parallel/test-http-upgrade-client.js +++ b/test/parallel/test-http-upgrade-client.js @@ -29,6 +29,7 @@ const assert = require('assert'); const http = require('http'); const net = require('net'); +const Countdown = require('../common/countdown'); // Create a TCP server const srv = net.createServer(function(c) { @@ -60,7 +61,8 @@ srv.listen(0, '127.0.0.1', common.mustCall(function() { ['Origin', 'http://www.websocket.org'] ] ]; - let left = headers.length; + const countdown = new Countdown(headers.length, () => srv.close()); + headers.forEach(function(h) { const req = http.get({ port: port, @@ -87,8 +89,7 @@ srv.listen(0, '127.0.0.1', common.mustCall(function() { assert.deepStrictEqual(expectedHeaders, res.headers); socket.end(); - if (--left === 0) - srv.close(); + countdown.dec(); })); req.on('close', common.mustCall(function() { assert.strictEqual(sawUpgrade, true);