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

Conversation

onneri
Copy link
Contributor

@onneri onneri commented Dec 6, 2017

The test was changed to use countdown instead of validating
if the index of the array of codes exceeded the size of the
array.

Also the validation that was before didn't allow to execute
the last test, so the assert equal was to 5, and the last
status in the array wasn't tested. The change was to
assert 6 tests complete.

Refs: #17169

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines
Affected core subsystem(s)

The test was changed to use countdown instead of validating
if the index of the array of codes exceeded the size of the
array.

Also the validation that was before didn't allow to execute
the last test, so the assert equal was to 5, and the last
status in the array wasn't tested. The change was to
assert 6 tests complete.

Fixes: nodejs#17169
@nodejs-github-bot nodejs-github-bot added the test Issues and PRs related to the tests. label Dec 6, 2017
});
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.

Copy link
Member

@apapirovski apapirovski left a comment

Choose a reason for hiding this comment

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

LGTM but some small changes needed

Thank you for taking this on!

});
response.resume();
});
}


process.on('exit', function() {
assert.strictEqual(5, testsComplete);
assert.strictEqual(6, testsComplete);
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.

@@ -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).

@@ -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;.


// 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;
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.

@@ -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.

The test was changed to use countdown instead of validating
if the index of the array of codes exceeded the size of the
array.

Also the validation that was before didn't allow to execute
the last test, so the assert equal was to 5, and the last
status in the array wasn't tested. The change was to
assert 6 tests complete.

Variable testIdx to manage index in array removed, using
array shift instead to manage the actual test.
Variable testsComplete removed, not necessary, Countdown
takes care of running right amount of tests
Added a test variable that has the actual code for testing

Fixes: nodejs#17169
@onneri
Copy link
Contributor Author

onneri commented Dec 6, 2017

You are right, I did't notice that assertEqual for tests completed wasn't necessary due to the Countdown variable.
I made some changes to the suggestions, if you have more comments please let me know, thank you!

Copy link
Member

@apapirovski apapirovski left a comment

Choose a reason for hiding this comment

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

Changes LGTM. Thank you!

@apapirovski
Copy link
Member

@onneri
Copy link
Contributor Author

onneri commented Dec 6, 2017

One test failed, could I do something about that?, or did I do something that produced that?

@apapirovski
Copy link
Member

Not your fault at all, the CI is all green as far as this PR is concerned. The failure is completely unrelated. :)

@maclover7 maclover7 added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Dec 8, 2017
apapirovski pushed a commit that referenced this pull request Dec 8, 2017
PR-URL: #17477
Refs: #17169
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Jon Moss <me@jonathanmoss.me>
@apapirovski
Copy link
Member

Landed in 07549c6

Thank you for your contribution @onneri! 👍

@apapirovski apapirovski closed this Dec 8, 2017
@onneri
Copy link
Contributor Author

onneri commented Dec 8, 2017

awesome, thank you, I'll try to contribute more times, @apapirovski what does "closed with unmerged commits" mean?

@apapirovski
Copy link
Member

apapirovski commented Dec 8, 2017

@onneri We don't use GitHub's buttons for merging, we have our own process for landing PRs so it just means that we didn't merge directly from your branch. As you'll note above, there's a reference to your commit landing on the master branch ("test: update http test to use Countdown"), listed right above my comment re: landing it.

Let me know if I can provide any more info! Thanks again for helping out. Looking forward to hopefully reviewing more PRs from you in the future :)

@onneri
Copy link
Contributor Author

onneri commented Dec 8, 2017

thank you again!

MylesBorins pushed a commit that referenced this pull request Dec 12, 2017
PR-URL: #17477
Refs: #17169
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Jon Moss <me@jonathanmoss.me>
MylesBorins pushed a commit that referenced this pull request Dec 12, 2017
PR-URL: #17477
Refs: #17169
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Jon Moss <me@jonathanmoss.me>
@MylesBorins MylesBorins mentioned this pull request Dec 12, 2017
@addaleax addaleax removed the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Dec 13, 2017
gibfahn pushed a commit that referenced this pull request Dec 20, 2017
PR-URL: #17477
Refs: #17169
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Jon Moss <me@jonathanmoss.me>
@gibfahn gibfahn mentioned this pull request Dec 20, 2017
gibfahn pushed a commit that referenced this pull request Dec 20, 2017
PR-URL: #17477
Refs: #17169
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Jon Moss <me@jonathanmoss.me>
@gibfahn gibfahn mentioned this pull request Dec 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
test Issues and PRs related to the tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants