Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 0 additions & 43 deletions test/parallel/test-net-autoselectfamily-local-port.js

This file was deleted.

37 changes: 37 additions & 0 deletions test/sequential/test-net-autoselectfamily-local-port.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
'use strict';

const common = require('../common');
if (!common.hasIPv6) common.skip('IPv6 loopback is unavailable');

const assert = require('node:assert');
const { createConnection, createServer } = require('node:net');
const { TCP } = process.binding('tcp_wrap');
// A pending IPv6 connect with a fixed source port must be closed before an
// IPv4 candidate binds to that port.
TCP.prototype.connect6 = function() {
return 0;
};

const server = createServer(common.mustCall((socket) => socket.end()));
server.listen(0, '127.0.0.1', common.mustCall(() => {
const port = server.address().port;
const connection = createConnection({
host: 'example.org',
port,
localPort: common.PORT,
lookup: common.mustCall((host, options, callback) => {
process.nextTick(callback, null, [
{ address: '::1', family: 6 },
{ address: '127.0.0.1', family: 4 },
]);
}),
autoSelectFamily: true,
autoSelectFamilyAttemptTimeout: 10,
});
connection.on('connect', common.mustCall(() => {
assert.strictEqual(connection.localPort, common.PORT);
assert.strictEqual(connection.remoteAddress, '127.0.0.1');
}));
connection.on('error', common.mustNotCall());
connection.on('close', common.mustCall(() => server.close()));
}));