forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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`. PR-URL: nodejs#6753 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
- Loading branch information
Showing
1 changed file
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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); | ||
} | ||
); | ||
socket.close(); | ||
} |