From 281de19a8c551b7da4f7e6d6d7393e797e945962 Mon Sep 17 00:00:00 2001 From: Artur Vieira Date: Fri, 12 May 2017 21:54:01 +0000 Subject: [PATCH] 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 Reviewed-By: Colin Ihrig --- .../parallel/test-dgram-send-address-types.js | 58 ++++++++++--------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/test/parallel/test-dgram-send-address-types.js b/test/parallel/test-dgram-send-address-types.js index d064898aa9fd86..6c5bf20e00db78 100644 --- a/test/parallel/test-dgram-send-address-types.js +++ b/test/parallel/test-dgram-send-address-types.js @@ -3,49 +3,51 @@ const common = require('../common'); const assert = require('assert'); const dgram = require('dgram'); -const port = common.PORT; const buf = Buffer.from('test'); -const client = dgram.createSocket('udp4'); const onMessage = common.mustCall((err, bytes) => { assert.ifError(err); assert.strictEqual(bytes, buf.length); }, 6); -// valid address: false -client.send(buf, port, false, onMessage); +const expectedError = + /^TypeError: Invalid arguments: address must be a nonempty string or falsy$/; -// valid address: empty string -client.send(buf, port, '', onMessage); +const client = dgram.createSocket('udp4').bind(0, () => { + const port = client.address().port; -// valid address: null -client.send(buf, port, null, onMessage); + // valid address: false + client.send(buf, port, false, onMessage); -// valid address: 0 -client.send(buf, port, 0, onMessage); + // valid address: empty string + client.send(buf, port, '', onMessage); -// valid address: undefined -client.send(buf, port, undefined, onMessage); + // valid address: null + client.send(buf, port, null, onMessage); -// valid address: not provided -client.send(buf, port, onMessage); + // valid address: 0 + client.send(buf, port, 0, onMessage); -const expectedError = - /^TypeError: Invalid arguments: address must be a nonempty string or falsy$/; + // 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: object + assert.throws(() => { + client.send(buf, port, []); + }, expectedError); -// invalid address: nonzero number -assert.throws(() => { - client.send(buf, port, 1); -}, expectedError); + // invalid address: nonzero number + assert.throws(() => { + client.send(buf, port, 1); + }, expectedError); -// invalid address: true -assert.throws(() => { - client.send(buf, port, true); -}, expectedError); + // invalid address: true + assert.throws(() => { + client.send(buf, port, true); + }, expectedError); +}); client.unref();