Skip to content

Commit 27107b9

Browse files
daxlabMylesBorins
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 1e8d120 commit 27107b9

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
@@ -3,8 +3,7 @@ require('../common');
33
const assert = require('assert');
44
const http = require('http');
55
const net = require('net');
6-
7-
let testsComplete = 0;
6+
const Countdown = require('../common/countdown');
87

98
const testCases = [
109
{ path: '/200', statusMessage: 'OK',
@@ -38,6 +37,8 @@ const server = net.createServer(function(connection) {
3837
});
3938
});
4039

40+
const countdown = new Countdown(testCases.length, () => server.close());
41+
4142
function runTest(testCaseIndex) {
4243
const testCase = testCases[testCaseIndex];
4344

@@ -50,12 +51,9 @@ function runTest(testCaseIndex) {
5051
assert.strictEqual(testCase.statusMessage, response.statusMessage);
5152

5253
response.on('end', function() {
53-
testsComplete++;
54-
54+
countdown.dec();
5555
if (testCaseIndex + 1 < testCases.length) {
5656
runTest(testCaseIndex + 1);
57-
} else {
58-
server.close();
5957
}
6058
});
6159

@@ -64,7 +62,3 @@ function runTest(testCaseIndex) {
6462
}
6563

6664
server.listen(0, function() { runTest(0); });
67-
68-
process.on('exit', function() {
69-
assert.strictEqual(testCases.length, testsComplete);
70-
});

0 commit comments

Comments
 (0)