Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
test: use countdown timer
PR-URL: #17326
Refs: #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 MylesBorins committed Feb 27, 2018
1 parent d554b8a commit 0e6cb3f
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions test/parallel/test-http-response-status-message.js
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 0e6cb3f

Please sign in to comment.