Skip to content

Commit

Permalink
test: use countdown timer
Browse files Browse the repository at this point in the history
PR-URL: #17326
Refs: #17169
Reviewed-By: Jon Moss <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
  • Loading branch information
daxlab authored and MylesBorins committed Feb 27, 2018
1 parent 1e8d120 commit 27107b9
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 @@ -3,8 +3,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 @@ -38,6 +37,8 @@ const server = net.createServer(function(connection) {
});
});

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

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

Expand All @@ -50,12 +51,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 @@ -64,7 +62,3 @@ function runTest(testCaseIndex) {
}

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

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

0 comments on commit 27107b9

Please sign in to comment.