Skip to content

Commit 9fc47de

Browse files
vieiraarturgjasnell
authored andcommitted
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: #13007 Refs: #12376 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 8ef4fe0 commit 9fc47de

File tree

1 file changed

+30
-28
lines changed

1 file changed

+30
-28
lines changed

test/parallel/test-dgram-send-address-types.js

+30-28
Original file line numberDiff line numberDiff line change
@@ -3,49 +3,51 @@ const common = require('../common');
33
const assert = require('assert');
44
const dgram = require('dgram');
55

6-
const port = common.PORT;
76
const buf = Buffer.from('test');
8-
const client = dgram.createSocket('udp4');
97

108
const onMessage = common.mustCall((err, bytes) => {
119
assert.ifError(err);
1210
assert.strictEqual(bytes, buf.length);
1311
}, 6);
1412

15-
// valid address: false
16-
client.send(buf, port, false, onMessage);
13+
const expectedError =
14+
/^TypeError: Invalid arguments: address must be a nonempty string or falsy$/;
1715

18-
// valid address: empty string
19-
client.send(buf, port, '', onMessage);
16+
const client = dgram.createSocket('udp4').bind(0, () => {
17+
const port = client.address().port;
2018

21-
// valid address: null
22-
client.send(buf, port, null, onMessage);
19+
// valid address: false
20+
client.send(buf, port, false, onMessage);
2321

24-
// valid address: 0
25-
client.send(buf, port, 0, onMessage);
22+
// valid address: empty string
23+
client.send(buf, port, '', onMessage);
2624

27-
// valid address: undefined
28-
client.send(buf, port, undefined, onMessage);
25+
// valid address: null
26+
client.send(buf, port, null, onMessage);
2927

30-
// valid address: not provided
31-
client.send(buf, port, onMessage);
28+
// valid address: 0
29+
client.send(buf, port, 0, onMessage);
3230

33-
const expectedError =
34-
/^TypeError: Invalid arguments: address must be a nonempty string or falsy$/;
31+
// valid address: undefined
32+
client.send(buf, port, undefined, onMessage);
33+
34+
// valid address: not provided
35+
client.send(buf, port, onMessage);
3536

36-
// invalid address: object
37-
assert.throws(() => {
38-
client.send(buf, port, []);
39-
}, expectedError);
37+
// invalid address: object
38+
assert.throws(() => {
39+
client.send(buf, port, []);
40+
}, expectedError);
4041

41-
// invalid address: nonzero number
42-
assert.throws(() => {
43-
client.send(buf, port, 1);
44-
}, expectedError);
42+
// invalid address: nonzero number
43+
assert.throws(() => {
44+
client.send(buf, port, 1);
45+
}, expectedError);
4546

46-
// invalid address: true
47-
assert.throws(() => {
48-
client.send(buf, port, true);
49-
}, expectedError);
47+
// invalid address: true
48+
assert.throws(() => {
49+
client.send(buf, port, true);
50+
}, expectedError);
51+
});
5052

5153
client.unref();

0 commit comments

Comments
 (0)