Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1549899

Browse filesBrowse files
TrottMyles Borins
authored andcommitted
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: #6753 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
1 parent 1c4549a commit 1549899
Copy full SHA for 1549899

File tree

Expand file treeCollapse file tree

1 file changed

+87
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+87
-0
lines changed
Open diff view settings
Collapse file
+87Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const assert = require('assert');
5+
const dgram = require('dgram');
6+
const multicastAddress = '224.0.0.114';
7+
8+
const setup = () => {
9+
return dgram.createSocket({type: 'udp4', reuseAddr: true});
10+
};
11+
12+
// addMembership() on closed socket should throw
13+
{
14+
const socket = setup();
15+
socket.close(common.mustCall(() => {
16+
assert.throws(() => { socket.addMembership(multicastAddress); },
17+
/Not running/);
18+
}));
19+
}
20+
21+
// dropMembership() on closed socket should throw
22+
{
23+
const socket = setup();
24+
socket.close(common.mustCall(() => {
25+
assert.throws(() => { socket.dropMembership(multicastAddress); },
26+
/Not running/);
27+
}));
28+
}
29+
30+
// addMembership() with no argument should throw
31+
{
32+
const socket = setup();
33+
assert.throws(() => { socket.addMembership(); },
34+
/multicast address must be specified/);
35+
socket.close();
36+
}
37+
38+
// dropMembership() with no argument should throw
39+
{
40+
const socket = setup();
41+
assert.throws(() => { socket.dropMembership(); },
42+
/multicast address must be specified/);
43+
socket.close();
44+
}
45+
46+
// addMembership() with invalid multicast address should throw
47+
{
48+
const socket = setup();
49+
assert.throws(() => { socket.addMembership('256.256.256.256'); }, /EINVAL/);
50+
socket.close();
51+
}
52+
53+
// dropMembership() with invalid multicast address should throw
54+
{
55+
const socket = setup();
56+
assert.throws(() => { socket.dropMembership('256.256.256.256'); }, /EINVAL/);
57+
socket.close();
58+
}
59+
60+
// addMembership() with valid socket and multicast address should not throw
61+
{
62+
const socket = setup();
63+
assert.doesNotThrow(() => { socket.addMembership(multicastAddress); });
64+
socket.close();
65+
}
66+
67+
// dropMembership() without previous addMembership should throw
68+
{
69+
const socket = setup();
70+
assert.throws(
71+
() => { socket.dropMembership(multicastAddress); },
72+
/EADDRNOTAVAIL/
73+
);
74+
socket.close();
75+
}
76+
77+
// dropMembership() after addMembership() should not throw
78+
{
79+
const socket = setup();
80+
assert.doesNotThrow(
81+
() => {
82+
socket.addMembership(multicastAddress);
83+
socket.dropMembership(multicastAddress);
84+
}
85+
);
86+
socket.close();
87+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.