test: use countdown timer

PR-URL: https://github.com/nodejs/node/pull/17326
Refs: https://github.com/nodejs/node/issues/17169
Reviewed-By: Jon Moss <me@jonathanmoss.me>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
Mandeep Singh authored and Evan Lucas committed 2018-01-30 14:25:17 -06:00
1 parent 0250e1b9c0
commit fc89cea5cd
1 file changed
+4 -10
@@ -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',
@@ -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];
@@ -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();
}
});
@@ -85,7 +83,3 @@ function runTest(testCaseIndex) {
}
server.listen(0, function() { runTest(0); });
process.on('exit', function() {
assert.strictEqual(testCases.length, testsComplete);
});