Skip to content

Commit 8638999

Browse files
yanivfriedensohntargos
authored andcommitted
test: add test for internalConnect() when address type is IPv6
PR-URL: #22444 Reviewed-By: Refael Ackermann <[email protected]>
1 parent 7f85288 commit 8638999

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

test/common/index.js

+4
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,10 @@ Object.defineProperty(exports, 'localhostIPv4', {
180180
}
181181
});
182182

183+
Object.defineProperty(exports, 'localhostIPv6', {
184+
get: () => '::1'
185+
});
186+
183187
// opensslCli defined lazily to reduce overhead of spawnSync
184188
Object.defineProperty(exports, 'opensslCli', { get: function() {
185189
if (opensslCli !== null) return opensslCli;

test/sequential/test-net-connect-local-error.js

+25-6
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,39 @@ const net = require('net');
66
// EADDRINUSE is expected to occur on FreeBSD
77
// Ref: https://github.com/nodejs/node/issues/13055
88
const expectedErrorCodes = ['ECONNREFUSED', 'EADDRINUSE'];
9-
const client = net.connect({
9+
10+
const optionsIPv4 = {
1011
port: common.PORT,
1112
localPort: common.PORT + 1,
1213
localAddress: common.localhostIPv4
13-
});
14+
};
15+
16+
const optionsIPv6 = {
17+
host: common.localhostIPv6,
18+
port: common.PORT + 2,
19+
localPort: common.PORT + 3,
20+
localAddress: common.localhostIPv6
21+
};
1422

15-
client.on('error', common.mustCall(function onError(err) {
23+
function onError(err, options) {
1624
assert.ok(expectedErrorCodes.includes(err.code));
1725
assert.strictEqual(err.syscall, 'connect');
18-
assert.strictEqual(err.localPort, common.PORT + 1);
19-
assert.strictEqual(err.localAddress, common.localhostIPv4);
26+
assert.strictEqual(err.localPort, options.localPort);
27+
assert.strictEqual(err.localAddress, options.localAddress);
2028
assert.strictEqual(
2129
err.message,
2230
`connect ${err.code} ${err.address}:${err.port} ` +
2331
`- Local (${err.localAddress}:${err.localPort})`
2432
);
25-
}));
33+
}
34+
35+
const clientIPv4 = net.connect(optionsIPv4);
36+
clientIPv4.on('error', common.mustCall((err) => onError(err, optionsIPv4)));
37+
38+
if (!common.hasIPv6) {
39+
common.printSkipMessage('ipv6 part of test, no IPv6 support');
40+
return;
41+
}
42+
43+
const clientIPv6 = net.connect(optionsIPv6);
44+
clientIPv6.on('error', common.mustCall((err) => onError(err, optionsIPv6)));

0 commit comments

Comments
 (0)