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

internet: improve assert message #15998

Closed

Conversation

nikkipelchat
Copy link

@nikkipelchat nikkipelchat commented Oct 6, 2017

Used default message to help with debugging when someone comes across this error.

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

internet

@nodejs-github-bot nodejs-github-bot added the test Issues and PRs related to the tests. label Oct 6, 2017
@@ -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}.`
Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

@Trott Trott Oct 9, 2017

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.

Copy link
Author

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

@mscdex mscdex added the dgram Issues and PRs related to the dgram subsystem / UDP. label Oct 6, 2017
@Trott Trott added the code-and-learn Issues related to the Code-and-Learn events and PRs submitted during the events. label Oct 7, 2017
jasnell
jasnell previously approved these changes Oct 13, 2017
@@ -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}.`
Copy link
Member

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.

Copy link
Author

@nikkipelchat nikkipelchat Oct 13, 2017

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

Copy link
Member

Choose a reason for hiding this comment

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

@nikkistonge I think you might be misunderstanding what @lpinca means in their comment. I think what @lpinca is trying to say is that messages.length and count should be swapped with each other in the message string added on line 157. It's backwards in the PR as it stands now.

Copy link
Author

Choose a reason for hiding this comment

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

Ok swapped them

@jasnell jasnell dismissed their stale review October 15, 2017 21:49

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}.`
Copy link
Member

@lpinca lpinca Oct 17, 2017

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.

Copy link
Author

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 :)

@joyeecheung
Copy link
Member

jasnell pushed a commit that referenced this pull request Oct 18, 2017
PR-URL: #15998
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Joyee Cheung <[email protected]>
Reviewed-By: James M Snell <[email protected]>
@jasnell
Copy link
Member

jasnell commented Oct 18, 2017

Landed in 9960e53. Thank you @nikkistonge!

@BridgeAR BridgeAR closed this Oct 18, 2017
@nikkipelchat nikkipelchat deleted the nikki/improve-assert-messages branch October 18, 2017 16:38
MylesBorins pushed a commit that referenced this pull request Oct 23, 2017
PR-URL: #15998
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Joyee Cheung <[email protected]>
Reviewed-By: James M Snell <[email protected]>
addaleax pushed a commit to ayojs/ayo that referenced this pull request Oct 26, 2017
PR-URL: nodejs/node#15998
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Joyee Cheung <[email protected]>
Reviewed-By: James M Snell <[email protected]>
MylesBorins pushed a commit that referenced this pull request Nov 16, 2017
PR-URL: #15998
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Joyee Cheung <[email protected]>
Reviewed-By: James M Snell <[email protected]>
@MylesBorins MylesBorins mentioned this pull request Nov 21, 2017
MylesBorins pushed a commit that referenced this pull request Nov 21, 2017
PR-URL: #15998
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Joyee Cheung <[email protected]>
Reviewed-By: James M Snell <[email protected]>
MylesBorins pushed a commit that referenced this pull request Nov 28, 2017
PR-URL: #15998
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Joyee Cheung <[email protected]>
Reviewed-By: James M Snell <[email protected]>
addaleax pushed a commit to ayojs/ayo that referenced this pull request Dec 7, 2017
PR-URL: nodejs/node#15998
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Joyee Cheung <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code-and-learn Issues related to the Code-and-Learn events and PRs submitted during the events. dgram Issues and PRs related to the dgram subsystem / UDP. test Issues and PRs related to the tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants