test: improving coverage for dgram
PR-URL: https://github.com/nodejs/node/pull/10783 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
parent
8e491a4f3f
commit
2057a63a91
12
test/parallel/test-dgram-multicast-loopback.js
Normal file
12
test/parallel/test-dgram-multicast-loopback.js
Normal file
@ -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();
|
||||||
|
}));
|
@ -1,23 +1,23 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
require('../common');
|
const common = require('../common');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const dgram = require('dgram');
|
const dgram = require('dgram');
|
||||||
const socket = dgram.createSocket('udp4');
|
const socket = dgram.createSocket('udp4');
|
||||||
let thrown = false;
|
|
||||||
|
|
||||||
socket.bind(0);
|
socket.bind(0);
|
||||||
socket.on('listening', function() {
|
socket.on('listening', common.mustCall(() => {
|
||||||
socket.setMulticastTTL(16);
|
const result = socket.setMulticastTTL(16);
|
||||||
|
assert.strictEqual(result, 16);
|
||||||
|
|
||||||
//Try to set an invalid TTL (valid ttl is > 0 and < 256)
|
//Try to set an invalid TTL (valid ttl is > 0 and < 256)
|
||||||
try {
|
assert.throws(() => {
|
||||||
socket.setMulticastTTL(1000);
|
socket.setMulticastTTL(1000);
|
||||||
} catch (e) {
|
}, /^Error: setMulticastTTL EINVAL$/);
|
||||||
thrown = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
//close the socket
|
||||||
socket.close();
|
socket.close();
|
||||||
});
|
}));
|
||||||
|
@ -1,17 +1,22 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
require('../common');
|
const common = require('../common');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const dgram = require('dgram');
|
const dgram = require('dgram');
|
||||||
const socket = dgram.createSocket('udp4');
|
const socket = dgram.createSocket('udp4');
|
||||||
|
|
||||||
socket.bind(0);
|
socket.bind(0);
|
||||||
socket.on('listening', function() {
|
socket.on('listening', common.mustCall(() => {
|
||||||
const result = socket.setTTL(16);
|
const result = socket.setTTL(16);
|
||||||
assert.strictEqual(result, 16);
|
assert.strictEqual(result, 16);
|
||||||
|
|
||||||
assert.throws(function() {
|
assert.throws(() => {
|
||||||
socket.setTTL('foo');
|
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();
|
socket.close();
|
||||||
});
|
}));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user