summaryrefslogtreecommitdiff
path: root/test/parallel/test-dgram-empty-packet.js
diff options
context:
space:
mode:
Diffstat (limited to 'test/parallel/test-dgram-empty-packet.js')
-rw-r--r--test/parallel/test-dgram-empty-packet.js39
1 files changed, 20 insertions, 19 deletions
diff --git a/test/parallel/test-dgram-empty-packet.js b/test/parallel/test-dgram-empty-packet.js
index 297072b37d..cdda183e2a 100644
--- a/test/parallel/test-dgram-empty-packet.js
+++ b/test/parallel/test-dgram-empty-packet.js
@@ -13,27 +13,28 @@ if (process.platform === 'darwin') {
client = dgram.createSocket('udp4');
-client.bind(common.PORT);
-
-function callback() {
- callbacks++;
- if (callbacks == 2) {
- clearTimeout(timer);
- client.close();
- } else if (callbacks > 2) {
- throw new Error('the callbacks should be called only two times');
+client.bind(0, function() {
+ function callback() {
+ callbacks++;
+ if (callbacks == 2) {
+ clearTimeout(timer);
+ client.close();
+ } else if (callbacks > 2) {
+ throw new Error('the callbacks should be called only two times');
+ }
}
-}
-
-client.on('message', function(buffer, bytes) {
- callback();
-});
-client.send(
- Buffer.allocUnsafe(1), 0, 0, common.PORT, '127.0.0.1', (err, len) => {
+ client.on('message', function(buffer, bytes) {
callback();
});
-timer = setTimeout(function() {
- throw new Error('Timeout');
-}, 200);
+ const port = this.address().port;
+ client.send(
+ Buffer.allocUnsafe(1), 0, 0, port, '127.0.0.1', (err, len) => {
+ callback();
+ });
+
+ timer = setTimeout(function() {
+ throw new Error('Timeout');
+ }, 200);
+});