Skip to content

Commit

Permalink
test: update test-http-upgrade-client to use countdown
Browse files Browse the repository at this point in the history
PR-URL: #17339
Reviewed-By: Jon Moss <[email protected]>
Reviewed-By: Anatoli Papirovski <[email protected]>
  • Loading branch information
mithunsasidharan authored and MylesBorins committed Dec 12, 2017
1 parent 91d5416 commit c9a4f4f
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions test/parallel/test-http-upgrade-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand All @@ -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);
Expand Down

0 comments on commit c9a4f4f

Please sign in to comment.