Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b54bc9c

Browse filesBrowse files
onnerigibfahn
authored andcommitted
test: update http test to use Countdown
PR-URL: #17477 Refs: #17169 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Jon Moss <me@jonathanmoss.me>
1 parent 4035686 commit b54bc9c
Copy full SHA for b54bc9c

File tree

Expand file treeCollapse file tree

1 file changed

+8
-17
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+8
-17
lines changed
Open diff view settings
Collapse file

‎test/parallel/test-http-status-code.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-http-status-code.js
+8-17Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,45 +23,36 @@
2323
require('../common');
2424
const assert = require('assert');
2525
const http = require('http');
26+
const Countdown = require('../common/countdown');
2627

2728
// Simple test of Node's HTTP ServerResponse.statusCode
2829
// ServerResponse.prototype.statusCode
2930

30-
let testsComplete = 0;
3131
const tests = [200, 202, 300, 404, 451, 500];
32-
let testIdx = 0;
32+
let test;
33+
const countdown = new Countdown(tests.length, () => s.close());
3334

3435
const s = http.createServer(function(req, res) {
35-
const t = tests[testIdx];
36-
res.writeHead(t, { 'Content-Type': 'text/plain' });
36+
res.writeHead(test, { 'Content-Type': 'text/plain' });
3737
console.log(`--\nserver: statusCode after writeHead: ${res.statusCode}`);
38-
assert.strictEqual(res.statusCode, t);
38+
assert.strictEqual(res.statusCode, test);
3939
res.end('hello world\n');
4040
});
4141

4242
s.listen(0, nextTest);
4343

4444

4545
function nextTest() {
46-
if (testIdx + 1 === tests.length) {
47-
return s.close();
48-
}
49-
const test = tests[testIdx];
46+
test = tests.shift();
5047

5148
http.get({ port: s.address().port }, function(response) {
5249
console.log(`client: expected status: ${test}`);
5350
console.log(`client: statusCode: ${response.statusCode}`);
5451
assert.strictEqual(response.statusCode, test);
5552
response.on('end', function() {
56-
testsComplete++;
57-
testIdx += 1;
58-
nextTest();
53+
if (countdown.dec())
54+
nextTest();
5955
});
6056
response.resume();
6157
});
6258
}
63-
64-
65-
process.on('exit', function() {
66-
assert.strictEqual(5, testsComplete);
67-
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.