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 ffdf605

Browse filesBrowse files
hiroppyItalo A. Casas
authored andcommitted
test: improving coverage for dgram
PR-URL: #10783 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 1666600 commit ffdf605
Copy full SHA for ffdf605

File tree

Expand file treeCollapse file tree

3 files changed

+32
-15
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+32
-15
lines changed
Open diff view settings
Collapse file
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const dgram = require('dgram');
5+
const socket = dgram.createSocket('udp4');
6+
7+
socket.bind(0);
8+
socket.on('listening', common.mustCall(() => {
9+
const result = socket.setMulticastLoopback(16);
10+
assert.strictEqual(result, 16);
11+
socket.close();
12+
}));
Collapse file
+10-10Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
'use strict';
2-
require('../common');
2+
const common = require('../common');
33
const assert = require('assert');
44
const dgram = require('dgram');
55
const socket = dgram.createSocket('udp4');
6-
let thrown = false;
76

87
socket.bind(0);
9-
socket.on('listening', function() {
10-
socket.setMulticastTTL(16);
8+
socket.on('listening', common.mustCall(() => {
9+
const result = socket.setMulticastTTL(16);
10+
assert.strictEqual(result, 16);
1111

1212
//Try to set an invalid TTL (valid ttl is > 0 and < 256)
13-
try {
13+
assert.throws(() => {
1414
socket.setMulticastTTL(1000);
15-
} catch (e) {
16-
thrown = true;
17-
}
15+
}, /^Error: setMulticastTTL EINVAL$/);
1816

19-
assert(thrown, 'Setting an invalid multicast TTL should throw some error');
17+
assert.throws(() => {
18+
socket.setMulticastTTL('foo');
19+
}, /^TypeError: Argument must be a number$/);
2020

2121
//close the socket
2222
socket.close();
23-
});
23+
}));
Collapse file

‎test/parallel/test-dgram-setTTL.js‎

Copy file name to clipboard
+10-5Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
'use strict';
2-
require('../common');
2+
const common = require('../common');
33
const assert = require('assert');
44
const dgram = require('dgram');
55
const socket = dgram.createSocket('udp4');
66

77
socket.bind(0);
8-
socket.on('listening', function() {
8+
socket.on('listening', common.mustCall(() => {
99
const result = socket.setTTL(16);
1010
assert.strictEqual(result, 16);
1111

12-
assert.throws(function() {
12+
assert.throws(() => {
1313
socket.setTTL('foo');
14-
}, /Argument must be a number/);
14+
}, /^TypeError: Argument must be a number$/);
15+
16+
// TTL must be a number from > 0 to < 256
17+
assert.throws(() => {
18+
socket.setTTL(1000);
19+
}, /^Error: setTTL EINVAL$/);
1520

1621
socket.close();
17-
});
22+
}));

0 commit comments

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