Skip to content

Commit

Permalink
test: use dynamic port in test-dgram-send-address-types
Browse files Browse the repository at this point in the history
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: #13007
Refs: #12376
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
  • Loading branch information
Artur Vieira authored and jasnell committed May 23, 2017
1 parent 8ef4fe0 commit 9fc47de
Showing 1 changed file with 30 additions and 28 deletions.
58 changes: 30 additions & 28 deletions test/parallel/test-dgram-send-address-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

0 comments on commit 9fc47de

Please sign in to comment.