Skip to content

Commit

Permalink
test: improving coverage for dgram
Browse files Browse the repository at this point in the history
PR-URL: #10783
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information
hiroppy authored and MylesBorins committed Mar 9, 2017
1 parent 017afd4 commit 6c1d82c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 16 deletions.
12 changes: 12 additions & 0 deletions test/parallel/test-dgram-multicast-loopback.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const socket = dgram.createSocket('udp4');

socket.bind(0);
socket.on('listening', common.mustCall(() => {
const result = socket.setMulticastLoopback(16);
assert.strictEqual(result, 16);
socket.close();
}));
20 changes: 10 additions & 10 deletions test/parallel/test-dgram-multicast-setTTL.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
'use strict';
require('../common');
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const socket = dgram.createSocket('udp4');
let thrown = false;

socket.bind(0);
socket.on('listening', function() {
socket.setMulticastTTL(16);
socket.on('listening', common.mustCall(() => {
const result = socket.setMulticastTTL(16);
assert.strictEqual(result, 16);

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

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

//close the socket
socket.close();
});
}));
17 changes: 11 additions & 6 deletions test/parallel/test-dgram-setTTL.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
'use strict';
require('../common');
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const socket = dgram.createSocket('udp4');

socket.bind(0);
socket.on('listening', function() {
var result = socket.setTTL(16);
socket.on('listening', common.mustCall(() => {
const result = socket.setTTL(16);
assert.strictEqual(result, 16);

assert.throws(function() {
assert.throws(() => {
socket.setTTL('foo');
}, /Argument must be a number/);
}, /^TypeError: Argument must be a number$/);

// TTL must be a number from > 0 to < 256
assert.throws(() => {
socket.setTTL(1000);
}, /^Error: setTTL EINVAL$/);

socket.close();
});
}));

0 comments on commit 6c1d82c

Please sign in to comment.