-
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
internet: improve assert message #15998
internet: improve assert message #15998
Conversation
@@ -153,7 +153,8 @@ if (process.argv[2] !== 'child') { | |||
assert.strictEqual( | |||
count, | |||
messages.length, | |||
'A worker received an invalid multicast message' | |||
`A worker received an invalid multicast message. | |||
Received ${messages.length} and wanted ${count}.` |
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 message includes extra spaces.
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 happens because it is a multi line template strings. In this case all spaces in the beginning of the second line are real spaces in the string. In Node.js we limit every string to a single line to prevent things like that. It should therefore either be changed now or while landing.
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.
Hi, @nikkistonge! Welcome and thanks for doing this. It would be acceptable to use concatenation here:
'A worker received an invalid multicast message.' +
`Received ${messages.length} and expected {$count}.`
That would address the comments above.
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.
Sorry about the delay, didn't see these comments.
I didn't know that was how template strings worked, I've only ever used them for SQL and html stuff and both don't care about extra spaces so I assumed they got removed.
Changed my code to remove them and added just one space after the first sentence. @Trott
@@ -153,7 +153,8 @@ if (process.argv[2] !== 'child') { | |||
assert.strictEqual( | |||
count, | |||
messages.length, | |||
'A worker received an invalid multicast message' | |||
'A worker received an invalid multicast message. ' + | |||
`Received ${messages.length} and wanted ${count}.` |
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.
Shouldn't this be Received ${count} and wanted ${messages.length}.
?
Personally I would just remove the "message" argument and use the default error message.
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.
No this is the right way I think, I asked at the code and learn to make sure. If they don't want the message they can close this PR
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.
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.
Ok swapped them
Looking it over again, the feedback is correct that the messages.length
and count
are reversed in the message.
@@ -153,7 +153,8 @@ if (process.argv[2] !== 'child') { | |||
assert.strictEqual( | |||
count, | |||
messages.length, | |||
'A worker received an invalid multicast message' | |||
'A worker received an invalid multicast message. ' + | |||
`Received ${count} and wanted ${messages.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.
@nikkistonge sorry to pester, but I think the message is still misleading.
If you look at the code, the above assertion is run only when all workers have received all the messages. After that the test validates that each message received by the workers matches the original using a counter for each worker. If the count does not match the assertion throws.
My point is that the "Received x and wanted y." feedback is wrong as all messages have actually been received but one ore more of them is invalid/corrupted.
If you could just refactor this into assert.strictEqual(count, messages.length);
that would be 10/10 imho as this will remove any possible confusion by using the default error message.
Thanks.
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.
Ok changed, now it will use default message :)
PR-URL: #15998 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Landed in 9960e53. Thank you @nikkistonge! |
PR-URL: #15998 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
PR-URL: nodejs/node#15998 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
PR-URL: #15998 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
PR-URL: #15998 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
PR-URL: #15998 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
PR-URL: nodejs/node#15998 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Used default message to help with debugging when someone comes across this error.
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
internet