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:
Artur Vieira 2017-05-12 21:54:01 +00:00 committed by Luigi Pinca
parent e00116d2c4
commit 281de19a8c

View File

@ -3,15 +3,19 @@ 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);
const expectedError =
/^TypeError: Invalid arguments: address must be a nonempty string or falsy$/;
const client = dgram.createSocket('udp4').bind(0, () => {
const port = client.address().port;
// valid address: false // valid address: false
client.send(buf, port, false, onMessage); client.send(buf, port, false, onMessage);
@ -30,9 +34,6 @@ client.send(buf, port, undefined, onMessage);
// valid address: not provided // valid address: not provided
client.send(buf, port, onMessage); client.send(buf, port, onMessage);
const expectedError =
/^TypeError: Invalid arguments: address must be a nonempty string or falsy$/;
// invalid address: object // invalid address: object
assert.throws(() => { assert.throws(() => {
client.send(buf, port, []); client.send(buf, port, []);
@ -47,5 +48,6 @@ assert.throws(() => {
assert.throws(() => { assert.throws(() => {
client.send(buf, port, true); client.send(buf, port, true);
}, expectedError); }, expectedError);
});
client.unref(); client.unref();