test: use dynamic port in test-dgram-send-address-types
Remove common.PORT from test-dgram-send-address-types to eliminate possibility that a dynamic port used in another test will collide with common.PORT. PR-URL: https://github.com/nodejs/node/pull/13007 Refs: https://github.com/nodejs/node/issues/12376 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
parent
e00116d2c4
commit
281de19a8c
@ -3,49 +3,51 @@ const common = require('../common');
|
|||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const dgram = require('dgram');
|
const dgram = require('dgram');
|
||||||
|
|
||||||
const port = common.PORT;
|
|
||||||
const buf = Buffer.from('test');
|
const buf = Buffer.from('test');
|
||||||
const client = dgram.createSocket('udp4');
|
|
||||||
|
|
||||||
const onMessage = common.mustCall((err, bytes) => {
|
const onMessage = common.mustCall((err, bytes) => {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
assert.strictEqual(bytes, buf.length);
|
assert.strictEqual(bytes, buf.length);
|
||||||
}, 6);
|
}, 6);
|
||||||
|
|
||||||
// valid address: false
|
|
||||||
client.send(buf, port, false, onMessage);
|
|
||||||
|
|
||||||
// valid address: empty string
|
|
||||||
client.send(buf, port, '', onMessage);
|
|
||||||
|
|
||||||
// valid address: null
|
|
||||||
client.send(buf, port, null, onMessage);
|
|
||||||
|
|
||||||
// valid address: 0
|
|
||||||
client.send(buf, port, 0, onMessage);
|
|
||||||
|
|
||||||
// valid address: undefined
|
|
||||||
client.send(buf, port, undefined, onMessage);
|
|
||||||
|
|
||||||
// valid address: not provided
|
|
||||||
client.send(buf, port, onMessage);
|
|
||||||
|
|
||||||
const expectedError =
|
const expectedError =
|
||||||
/^TypeError: Invalid arguments: address must be a nonempty string or falsy$/;
|
/^TypeError: Invalid arguments: address must be a nonempty string or falsy$/;
|
||||||
|
|
||||||
// invalid address: object
|
const client = dgram.createSocket('udp4').bind(0, () => {
|
||||||
assert.throws(() => {
|
const port = client.address().port;
|
||||||
client.send(buf, port, []);
|
|
||||||
}, expectedError);
|
|
||||||
|
|
||||||
// invalid address: nonzero number
|
// valid address: false
|
||||||
assert.throws(() => {
|
client.send(buf, port, false, onMessage);
|
||||||
client.send(buf, port, 1);
|
|
||||||
}, expectedError);
|
|
||||||
|
|
||||||
// invalid address: true
|
// valid address: empty string
|
||||||
assert.throws(() => {
|
client.send(buf, port, '', onMessage);
|
||||||
client.send(buf, port, true);
|
|
||||||
}, expectedError);
|
// valid address: null
|
||||||
|
client.send(buf, port, null, onMessage);
|
||||||
|
|
||||||
|
// valid address: 0
|
||||||
|
client.send(buf, port, 0, onMessage);
|
||||||
|
|
||||||
|
// valid address: undefined
|
||||||
|
client.send(buf, port, undefined, onMessage);
|
||||||
|
|
||||||
|
// valid address: not provided
|
||||||
|
client.send(buf, port, onMessage);
|
||||||
|
|
||||||
|
// invalid address: object
|
||||||
|
assert.throws(() => {
|
||||||
|
client.send(buf, port, []);
|
||||||
|
}, expectedError);
|
||||||
|
|
||||||
|
// invalid address: nonzero number
|
||||||
|
assert.throws(() => {
|
||||||
|
client.send(buf, port, 1);
|
||||||
|
}, expectedError);
|
||||||
|
|
||||||
|
// invalid address: true
|
||||||
|
assert.throws(() => {
|
||||||
|
client.send(buf, port, true);
|
||||||
|
}, expectedError);
|
||||||
|
});
|
||||||
|
|
||||||
client.unref();
|
client.unref();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user