Skip to content

Commit

Permalink
test: use countdown timer
Browse files Browse the repository at this point in the history
PR-URL: nodejs#17326
Refs: nodejs#17169
Reviewed-By: Jon Moss <me@jonathanmoss.me>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
  • Loading branch information
daxlab authored and MayaLekova committed May 8, 2018
1 parent cba0fc8 commit a845978
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions test/parallel/test-http-response-status-message.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ require('../common');
const assert = require('assert');
const http = require('http');
const net = require('net');

let testsComplete = 0;
const Countdown = require('../common/countdown');

const testCases = [
{ path: '/200', statusMessage: 'OK',
Expand Down Expand Up @@ -59,6 +58,8 @@ const server = net.createServer(function(connection) {
});
});

const countdown = new Countdown(testCases.length, () => server.close());

function runTest(testCaseIndex) {
const testCase = testCases[testCaseIndex];

Expand All @@ -71,12 +72,9 @@ function runTest(testCaseIndex) {
assert.strictEqual(testCase.statusMessage, response.statusMessage);

response.on('end', function() {
testsComplete++;

countdown.dec();
if (testCaseIndex + 1 < testCases.length) {
runTest(testCaseIndex + 1);
} else {
server.close();
}
});

Expand All @@ -85,7 +83,3 @@ function runTest(testCaseIndex) {
}

server.listen(0, function() { runTest(0); });

process.on('exit', function() {
assert.strictEqual(testCases.length, testsComplete);
});

0 comments on commit a845978

Please sign in to comment.