Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

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
Trott committed May 19, 2016
commit 57b62f5fafbf2ebbcf6693337bd3087e328ee6fe
87 changes: 87 additions & 0 deletions test/parallel/test-dgram-membership.js
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';
Copy link
Copy Markdown
Contributor

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?

Copy link
Copy Markdown
Member Author

@Trott Trott May 16, 2016

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 common will signal to people (like me) who don't fully understand multicast that it's OK for tests in parallel and sequential to communicate with that address. It's not, I don't think, and that's probably why the existing test that uses that address is in internet.

This test needs to have an address to test addMembership() and dropMembership(), 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."

Copy link
Copy Markdown
Member Author

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...

Copy link
Copy Markdown
Member

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.


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);
}
);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Missing socket.close()?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@bnoordhuis Yes, good catch. Added socket.close(), rebased against current master, force pushed.

socket.close();
}