-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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: refactoring test with common.mustCall #12702
Conversation
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.
Taking a quick look, there are a couple other places where common.mustCall()
could be added, e.g. server.listen(
, https.request(
, etc.
test/parallel/test-https-simple.js
Outdated
if (successful === tests) { | ||
server.close(); | ||
} | ||
server.close(); |
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.
When this is run later, it picks up the server
variable still? 🤔😖
Maybe we should make this into a function declaration (no assignment) and put it at the bottom of the file for clarity.
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.
server.close()
is within the testSucceeded function? and it is only called after this
checkCertReq.on('error', function(e) {
assert.strictEqual(e.code, 'UNABLE_TO_VERIFY_LEAF_SIGNATURE');
testSucceeded();
})
@ line 100
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.
I would prefer you change it to a function declaration (function testSucceeded()
without the const ... =
.) and move it to the bottom of the file. That should be more clear.
What's going on with the first three commits? |
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.
I'm not too sure how those were generated or even committed actually.
test/parallel/test-https-simple.js
Outdated
if (successful === tests) { | ||
server.close(); | ||
} | ||
server.close(); |
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.
server.close()
is within the testSucceeded function? and it is only called after this
checkCertReq.on('error', function(e) {
assert.strictEqual(e.code, 'UNABLE_TO_VERIFY_LEAF_SIGNATURE');
testSucceeded();
})
@ line 100
changed testSucceeded to a function declaration and put it at the bottom of the file |
test/parallel/test-https-simple.js
Outdated
@@ -55,7 +45,7 @@ const serverCallback = common.mustCall(function(req, res) { | |||
|
|||
const server = https.createServer(options, serverCallback); | |||
|
|||
server.listen(0, function() { | |||
server.listen(0, function(){ |
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.
Please add the space back. Does this pass make jslint
?
test/parallel/test-https-simple.js
Outdated
@@ -66,16 +56,15 @@ server.listen(0, function() { | |||
}; | |||
noCertCheckOptions.Agent = new https.Agent(noCertCheckOptions); | |||
|
|||
const req = https.request(noCertCheckOptions, function(res) { | |||
const req = https.request(noCertCheckOptions, function(res){ |
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.
Same comment here.
let responseBody = ''; | ||
res.on('data', function(d) { | ||
responseBody = responseBody + d; | ||
}); | ||
|
||
res.on('end', function() { | ||
res.on('end', common.mustCall(() => { |
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.
The enclosing https.request()
and server.listen()
callbacks need to have common.mustCall()
too, or there is no guarantee that this will execute.
test/parallel/test-https-simple.js
Outdated
process.on('exit', function() { | ||
assert.strictEqual(successful, tests); | ||
}); | ||
function testSucceeded (){ |
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.
function testSucceeded() {
test/parallel/test-https-simple.js
Outdated
assert.strictEqual(successful, tests); | ||
}); | ||
function testSucceeded (){ | ||
server.close(); |
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.
Since this is only called from one place, you can just inline the server.close()
there.
after adding common.mustCall to server.listen, it resulted in the above error. So I had to define const port = server.address().port. |
@weewey that error was most likely because of the change from a function to an arrow function, not the use of |
Looking at the entire test, it looks like this has a race condition now. There are two parallel requests made, and the server is closed when the |
@cjihrig Thanks for helping to review. Yes true. I think it will be better if I bring back the assert but keeping the common.mustCall. So only after both requests are made, then server.close() is ran. |
…efore server is closed. Adding common.mustCall to checkCertReq.
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 if the CI passes.
@weewey can you please rebase against master and resolve conflicts? Although GitHub doesn't report any issues, the patch doesn't land cleanly. |
Landed in 152966d, thanks for the PR! :) |
PR-URL: #12702 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
PR-URL: nodejs#12702 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
PR-URL: #12702 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
PR-URL: #12702 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
test: refactoring test with common.mustCall
Removed assert.strictEqual using common.mustCall
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)