Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: update test-http-status-code to use countdown #17477

Closed
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions test/parallel/test-http-status-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@
require('../common');
const assert = require('assert');
const http = require('http');
const Countdown = require('../common/countdown');

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

let testsComplete = 0;
const tests = [200, 202, 300, 404, 451, 500];
let testIdx = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

testsComplete and testIdx can be removed. Instead add let test;.

const countdown = new Countdown(tests.length, () => s.close());

const s = http.createServer(function(req, res) {
const t = tests[testIdx];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be removed and then the assert.strictEqual() can compare to the top scope test variable.

Expand All @@ -43,9 +45,6 @@ s.listen(0, nextTest);


function nextTest() {
if (testIdx + 1 === tests.length) {
return s.close();
}
const test = tests[testIdx];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can just do test = tests.shift() here (and not declare it as a const).


http.get({ port: s.address().port }, function(response) {
Expand All @@ -55,13 +54,14 @@ function nextTest() {
response.on('end', function() {
testsComplete++;
testIdx += 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These variable additions would both be removed.

nextTest();
if (countdown.dec())
nextTest();
});
response.resume();
});
}


process.on('exit', function() {
assert.strictEqual(5, testsComplete);
assert.strictEqual(6, testsComplete);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about replacing 6 with tests.length ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code can actually be removed, as well as the testsComplete variable. Since there's a Countdown now, there's no need to verify that all 6 test cases executed.

});