Skip to content

Commit fc89cea

Browse files
daxlabevanlucas
authored andcommitted
test: use countdown timer
PR-URL: #17326 Refs: #17169 Reviewed-By: Jon Moss <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent 0250e1b commit fc89cea

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

test/parallel/test-http-response-status-message.js

+4-10
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ require('../common');
2424
const assert = require('assert');
2525
const http = require('http');
2626
const net = require('net');
27-
28-
let testsComplete = 0;
27+
const Countdown = require('../common/countdown');
2928

3029
const testCases = [
3130
{ path: '/200', statusMessage: 'OK',
@@ -59,6 +58,8 @@ const server = net.createServer(function(connection) {
5958
});
6059
});
6160

61+
const countdown = new Countdown(testCases.length, () => server.close());
62+
6263
function runTest(testCaseIndex) {
6364
const testCase = testCases[testCaseIndex];
6465

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

7374
response.on('end', function() {
74-
testsComplete++;
75-
75+
countdown.dec();
7676
if (testCaseIndex + 1 < testCases.length) {
7777
runTest(testCaseIndex + 1);
78-
} else {
79-
server.close();
8078
}
8179
});
8280

@@ -85,7 +83,3 @@ function runTest(testCaseIndex) {
8583
}
8684

8785
server.listen(0, function() { runTest(0); });
88-
89-
process.on('exit', function() {
90-
assert.strictEqual(testCases.length, testsComplete);
91-
});

0 commit comments

Comments
 (0)