diff --git a/test/internet/test-dgram-connect.js b/test/internet/test-dgram-connect.js new file mode 100644 index 00000000000000..785181cee6bed3 --- /dev/null +++ b/test/internet/test-dgram-connect.js @@ -0,0 +1,21 @@ +'use strict'; + +const common = require('../common'); +const { addresses } = require('../common/internet'); +const assert = require('assert'); +const dgram = require('dgram'); + +const PORT = 12345; + +const client = dgram.createSocket('udp4'); +client.connect(PORT, addresses.INVALID_HOST, common.mustCall((err) => { + assert.ok(err.code === 'ENOTFOUND' || err.code === 'EAI_AGAIN'); + + client.once('error', common.mustCall((err) => { + assert.ok(err.code === 'ENOTFOUND' || err.code === 'EAI_AGAIN'); + client.once('connect', common.mustCall(() => client.close())); + client.connect(PORT); + })); + + client.connect(PORT, addresses.INVALID_HOST); +})); diff --git a/test/parallel/test-dgram-connect.js b/test/parallel/test-dgram-connect.js index 8fba27bcd2ac83..a9815f439a731a 100644 --- a/test/parallel/test-dgram-connect.js +++ b/test/parallel/test-dgram-connect.js @@ -1,7 +1,6 @@ 'use strict'; const common = require('../common'); -const { addresses } = require('../common/internet'); const assert = require('assert'); const dgram = require('dgram'); @@ -36,17 +35,8 @@ client.connect(PORT, common.mustCall(() => { code: 'ERR_SOCKET_DGRAM_NOT_CONNECTED' }); - client.connect(PORT, addresses.INVALID_HOST, common.mustCall((err) => { - assert.ok(err.code === 'ENOTFOUND' || err.code === 'EAI_AGAIN'); - - client.once('error', common.mustCall((err) => { - assert.ok(err.code === 'ENOTFOUND' || err.code === 'EAI_AGAIN'); - client.once('connect', common.mustCall(() => client.close())); - client.connect(PORT); - })); - - client.connect(PORT, addresses.INVALID_HOST); - })); + client.once('connect', common.mustCall(() => client.close())); + client.connect(PORT); })); assert.throws(() => {