-
Notifications
You must be signed in to change notification settings - Fork 30k
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
Conversation
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
}); | ||
response.resume(); | ||
}); | ||
} | ||
|
||
|
||
process.on('exit', function() { | ||
assert.strictEqual(5, testsComplete); | ||
assert.strictEqual(6, testsComplete); |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
There was a problem hiding this 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); |
There was a problem hiding this comment.
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]; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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]; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
You are right, I did't notice that assertEqual for tests completed wasn't necessary due to the Countdown variable. |
There was a problem hiding this 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!
One test failed, could I do something about that?, or did I do something that produced that? |
Not your fault at all, the CI is all green as far as this PR is concerned. The failure is completely unrelated. :) |
PR-URL: #17477 Refs: #17169 Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Jon Moss <[email protected]>
awesome, thank you, I'll try to contribute more times, @apapirovski what does "closed with unmerged commits" mean? |
@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 :) |
thank you again! |
PR-URL: #17477 Refs: #17169 Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Jon Moss <[email protected]>
PR-URL: #17477 Refs: #17169 Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Jon Moss <[email protected]>
PR-URL: #17477 Refs: #17169 Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Jon Moss <[email protected]>
PR-URL: #17477 Refs: #17169 Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Jon Moss <[email protected]>
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), orvcbuild test
(Windows) passesAffected core subsystem(s)