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:
parent
080a72c349
commit
7d2b08a3b5
@ -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);
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user