-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
dgram,test: add addMembership/dropMembership tests #6753
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev
Previous commit
dgram,test: add addMembership/dropMembership tests
The only tests for `addMembership()` and `dropMembership()` (from the `dgram` module) were in `test/internet` which means they almost never get run. This adds checks in `test/parallel`. I also did some minor tidying on the existing `test/internet` test.
- Loading branch information
commit 57b62f5fafbf2ebbcf6693337bd3087e328ee6fe
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| 'use strict'; | ||
|
|
||
| const common = require('../common'); | ||
| const assert = require('assert'); | ||
| const dgram = require('dgram'); | ||
| const multicastAddress = '224.0.0.114'; | ||
|
|
||
| const setup = () => { | ||
| return dgram.createSocket({type: 'udp4', reuseAddr: true}); | ||
| }; | ||
|
|
||
| // addMembership() on closed socket should throw | ||
| { | ||
| const socket = setup(); | ||
| socket.close(common.mustCall(() => { | ||
| assert.throws(() => { socket.addMembership(multicastAddress); }, | ||
| /Not running/); | ||
| })); | ||
| } | ||
|
|
||
| // dropMembership() on closed socket should throw | ||
| { | ||
| const socket = setup(); | ||
| socket.close(common.mustCall(() => { | ||
| assert.throws(() => { socket.dropMembership(multicastAddress); }, | ||
| /Not running/); | ||
| })); | ||
| } | ||
|
|
||
| // addMembership() with no argument should throw | ||
| { | ||
| const socket = setup(); | ||
| assert.throws(() => { socket.addMembership(); }, | ||
| /multicast address must be specified/); | ||
| socket.close(); | ||
| } | ||
|
|
||
| // dropMembership() with no argument should throw | ||
| { | ||
| const socket = setup(); | ||
| assert.throws(() => { socket.dropMembership(); }, | ||
| /multicast address must be specified/); | ||
| socket.close(); | ||
| } | ||
|
|
||
| // addMembership() with invalid multicast address should throw | ||
| { | ||
| const socket = setup(); | ||
| assert.throws(() => { socket.addMembership('256.256.256.256'); }, /EINVAL/); | ||
| socket.close(); | ||
| } | ||
|
|
||
| // dropMembership() with invalid multicast address should throw | ||
| { | ||
| const socket = setup(); | ||
| assert.throws(() => { socket.dropMembership('256.256.256.256'); }, /EINVAL/); | ||
| socket.close(); | ||
| } | ||
|
|
||
| // addMembership() with valid socket and multicast address should not throw | ||
| { | ||
| const socket = setup(); | ||
| assert.doesNotThrow(() => { socket.addMembership(multicastAddress); }); | ||
| socket.close(); | ||
| } | ||
|
|
||
| // dropMembership() without previous addMembership should throw | ||
| { | ||
| const socket = setup(); | ||
| assert.throws( | ||
| () => { socket.dropMembership(multicastAddress); }, | ||
| /EADDRNOTAVAIL/ | ||
| ); | ||
| socket.close(); | ||
| } | ||
|
|
||
| // dropMembership() after addMembership() should not throw | ||
| { | ||
| const socket = setup(); | ||
| assert.doesNotThrow( | ||
| () => { | ||
| socket.addMembership(multicastAddress); | ||
| socket.dropMembership(multicastAddress); | ||
| } | ||
| ); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @bnoordhuis Yes, good catch. Added |
||
| socket.close(); | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is this something that could be moved to
common?Uh oh!
There was an error while loading. Please reload this page.
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 on the fence on that. I have a concern that putting that address in
commonwill signal to people (like me) who don't fully understand multicast that it's OK for tests inparallelandsequentialto communicate with that address. It's not, I don't think, and that's probably why the existing test that uses that address is ininternet.This test needs to have an address to test
addMembership()anddropMembership(), which, now that I think about it, I guess means that this test will cause some IGMP traffic on the local network?/cc @nodejs/build in the hopes someone who actually understands how multicast works can say "Yup, this test will send a packet" or "Nope, this test does not send a packet on the network."
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.
Hmmm, although 224.0.0.114 would be multicast on the local subnet only, so maybe it's OK in the context of this test? Like, it's not sending packets destined for the Internet or anything...
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 can't say for sure it's true for all platforms but just joining or leaving a local multicast group (which all 224.0.0.xxx addresses are) should not generate any traffic, that's just bookkeeping to the kernel.