From 963fce858a6c7d7bb74496e22dfcb3434a971441 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Mon, 16 May 2016 14:56:30 -0700 Subject: [PATCH 1/2] doc: add `added:` info for dgram.*Membership() Since I was doing the necessary git archaeology anyway, I took the time to add YAML information to the docs about when `addMembership()` and `dropMembership()` first appeared in their current forms. --- doc/api/dgram.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/doc/api/dgram.md b/doc/api/dgram.md index 953d4bf8c9c0b3..7a09c9385a82a6 100644 --- a/doc/api/dgram.md +++ b/doc/api/dgram.md @@ -71,6 +71,9 @@ socket.on('message', (msg, rinfo) => { ``` ### socket.addMembership(multicastAddress[, multicastInterface]) + * `multicastAddress` {String} * `multicastInterface` {String}, Optional @@ -173,6 +176,9 @@ Close the underlying socket and stop listening for data on it. If a callback is provided, it is added as a listener for the [`'close'`][] event. ### socket.dropMembership(multicastAddress[, multicastInterface]) + * `multicastAddress` {String} * `multicastInterface` {String}, Optional From 57b62f5fafbf2ebbcf6693337bd3087e328ee6fe Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Mon, 16 May 2016 14:59:52 -0700 Subject: [PATCH 2/2] 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. --- test/parallel/test-dgram-membership.js | 87 ++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 test/parallel/test-dgram-membership.js diff --git a/test/parallel/test-dgram-membership.js b/test/parallel/test-dgram-membership.js new file mode 100644 index 00000000000000..ed5fb2897cbd3a --- /dev/null +++ b/test/parallel/test-dgram-membership.js @@ -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); + } + ); + socket.close(); +}