summaryrefslogtreecommitdiff
path: root/test/parallel/test-dgram-close.js
diff options
context:
space:
mode:
authorSebastian Plesciuc <sebastian.plesciuc@sendgrid.com>2017-04-24 17:20:41 +0300
committerAnna Henningsen <anna@addaleax.net>2017-04-27 17:20:21 +0200
commitd289678352427adba634ee61ee4a70822e08a03e (patch)
treec364405b6385786c587db0045703302f26704683 /test/parallel/test-dgram-close.js
parent28f535a923f14a303ffc23d7082f4def2ff2b554 (diff)
downloadandroid-node-v8-d289678352427adba634ee61ee4a70822e08a03e.tar.gz
android-node-v8-d289678352427adba634ee61ee4a70822e08a03e.tar.bz2
android-node-v8-d289678352427adba634ee61ee4a70822e08a03e.zip
test: dynamic port in dgram tests
Removed common.PORT from test-dgram-close-in-listening, test-dgram-close-is-not-callback, test-dgram-close, test-dgram-exclusive-implicit-bind and test-dgram-oob-buffer in order to eliminate the possibility of port collision. Refs: https://github.com/nodejs/node/issues/12376 PR-URL: https://github.com/nodejs/node/pull/12623 Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'test/parallel/test-dgram-close.js')
-rw-r--r--test/parallel/test-dgram-close.js31
1 files changed, 20 insertions, 11 deletions
diff --git a/test/parallel/test-dgram-close.js b/test/parallel/test-dgram-close.js
index 65c8a4d0df..01aadf2aef 100644
--- a/test/parallel/test-dgram-close.js
+++ b/test/parallel/test-dgram-close.js
@@ -32,14 +32,23 @@ const buf = Buffer.alloc(1024, 42);
let socket = dgram.createSocket('udp4');
const handle = socket._handle;
-socket.send(buf, 0, buf.length, common.PORT, 'localhost');
-assert.strictEqual(socket.close(common.mustCall()), socket);
-socket.on('close', common.mustCall());
-socket = null;
-
-// Verify that accessing handle after closure doesn't throw
-setImmediate(function() {
- setImmediate(function() {
- console.log('Handle fd is: ', handle.fd);
- });
-});
+// get a random port for send
+const portGetter = dgram.createSocket('udp4')
+ .bind(0, 'localhost', common.mustCall(() => {
+ socket.send(buf, 0, buf.length,
+ portGetter.address().port,
+ portGetter.address().address);
+
+ assert.strictEqual(socket.close(common.mustCall()), socket);
+ socket.on('close', common.mustCall());
+ socket = null;
+
+ // Verify that accessing handle after closure doesn't throw
+ setImmediate(function() {
+ setImmediate(function() {
+ console.log('Handle fd is: ', handle.fd);
+ });
+ });
+
+ portGetter.close();
+ }));