-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
dgram,test: add addMembership/dropMembership tests #6753
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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'; | ||
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. Is this something that could be moved to 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. I'm on the fence on that. I have a concern that putting that address in This test needs to have an address to test /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 commentThe 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 commentThe 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. |
||
|
||
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); | ||
} | ||
); | ||
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 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(); | ||
} |
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.
These should likely be done as a separate commit
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.
Done!