test: refactoring test with common.mustCall#12702
test: refactoring test with common.mustCall#12702weewey wants to merge 3 commits intonodejs:masterfrom
Conversation
Fishrock123
left a comment
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
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.
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? |
weewey
left a comment
There was a problem hiding this comment.
I'm not too sure how those were generated or even committed actually.
test/parallel/test-https-simple.js
Outdated
There was a problem hiding this comment.
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
| const server = https.createServer(options, serverCallback); | ||
|
|
||
| server.listen(0, function() { | ||
| server.listen(0, function(){ |
There was a problem hiding this comment.
Please add the space back. Does this pass make jslint?
test/parallel/test-https-simple.js
Outdated
| noCertCheckOptions.Agent = new https.Agent(noCertCheckOptions); | ||
|
|
||
| const req = https.request(noCertCheckOptions, function(res) { | ||
| const req = https.request(noCertCheckOptions, function(res){ |
| }); | ||
|
|
||
| res.on('end', function() { | ||
| res.on('end', common.mustCall(() => { |
There was a problem hiding this comment.
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.
function testSucceeded() {
test/parallel/test-https-simple.js
Outdated
| assert.strictEqual(successful, tests); | ||
| }); | ||
| function testSucceeded (){ | ||
| server.close(); |
There was a problem hiding this comment.
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.
|
@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)