diff options
author | Paolo Insogna <paolo@cowtech.it> | 2023-02-23 10:55:04 +0100 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2023-04-05 08:31:56 -0700 |
commit | 8b51c1a8696ae263141d18b39cbd144d2866f7c7 (patch) | |
tree | 42892f4bb6178fa096a6444d06eecd5896dda9c8 /test | |
parent | 069365c5bd63b8ed483a75e3791aae8f35ddf8c8 (diff) | |
download | node-new-8b51c1a8696ae263141d18b39cbd144d2866f7c7.tar.gz |
net: enable autoSelectFamily by default
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/46790
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/common/index.js | 10 | ||||
-rw-r--r-- | test/internet/test-tls-autoselectfamily-servername.js | 4 | ||||
-rw-r--r-- | test/parallel/test-http-autoselectfamily.js | 4 | ||||
-rw-r--r-- | test/parallel/test-http2-ping-settings-heapdump.js | 11 | ||||
-rw-r--r-- | test/parallel/test-https-autoselectfamily.js | 4 | ||||
-rw-r--r-- | test/parallel/test-net-autoselectfamily-commandline-option.js | 34 | ||||
-rw-r--r-- | test/parallel/test-net-autoselectfamily-default.js (renamed from test/parallel/test-net-autoselectfamilydefault.js) | 6 | ||||
-rw-r--r-- | test/parallel/test-net-autoselectfamily-ipv4first.js | 5 | ||||
-rw-r--r-- | test/parallel/test-net-autoselectfamily.js | 4 | ||||
-rw-r--r-- | test/parallel/test-tls-connect-hints-option.js | 2 | ||||
-rw-r--r-- | test/sequential/test-http-econnrefused.js | 6 | ||||
-rw-r--r-- | test/sequential/test-net-better-error-messages-port.js | 11 | ||||
-rw-r--r-- | test/sequential/test-net-connect-econnrefused.js | 7 | ||||
-rw-r--r-- | test/sequential/test-net-reconnect-error.js | 7 |
14 files changed, 51 insertions, 64 deletions
diff --git a/test/common/index.js b/test/common/index.js index eff02f3028..51a5acd32c 100644 --- a/test/common/index.js +++ b/test/common/index.js @@ -26,6 +26,7 @@ const process = global.process; // Some tests tamper with the process global. const assert = require('assert'); const { exec, execSync, spawn, spawnSync } = require('child_process'); const fs = require('fs'); +const net = require('net'); // Do not require 'os' until needed so that test-os-checked-function can // monkey patch it. If 'os' is required here, that test will fail. const path = require('path'); @@ -137,6 +138,14 @@ const isPi = (() => { const isDumbTerminal = process.env.TERM === 'dumb'; +// When using high concurrency or in the CI we need much more time for each connection attempt +const defaultAutoSelectFamilyAttemptTimeout = platformTimeout(2500); +// Since this is also used by tools outside of the test suite, +// make sure setDefaultAutoSelectFamilyAttemptTimeout +if (typeof net.setDefaultAutoSelectFamilyAttemptTimeout === 'function') { + net.setDefaultAutoSelectFamilyAttemptTimeout(platformTimeout(defaultAutoSelectFamilyAttemptTimeout)); +} + const buildType = process.config.target_defaults ? process.config.target_defaults.default_configuration : 'Release'; @@ -886,6 +895,7 @@ const common = { canCreateSymLink, childShouldThrowAndAbort, createZeroFilledFile, + defaultAutoSelectFamilyAttemptTimeout, expectsError, expectWarning, gcUntil, diff --git a/test/internet/test-tls-autoselectfamily-servername.js b/test/internet/test-tls-autoselectfamily-servername.js index ae53875b67..26f51ae602 100644 --- a/test/internet/test-tls-autoselectfamily-servername.js +++ b/test/internet/test-tls-autoselectfamily-servername.js @@ -7,12 +7,8 @@ if (!common.hasCrypto) { common.skip('missing crypto'); } -const { setDefaultAutoSelectFamilyAttemptTimeout } = require('net'); const { connect } = require('tls'); -// Some of the windows machines in the CI need more time to establish connection -setDefaultAutoSelectFamilyAttemptTimeout(common.platformTimeout(common.isWindows ? 1500 : 250)); - // Test that TLS connecting works without autoSelectFamily { const socket = connect({ diff --git a/test/parallel/test-http-autoselectfamily.js b/test/parallel/test-http-autoselectfamily.js index 6749d960f9..b98aacea7f 100644 --- a/test/parallel/test-http-autoselectfamily.js +++ b/test/parallel/test-http-autoselectfamily.js @@ -7,13 +7,9 @@ const assert = require('assert'); const dgram = require('dgram'); const { Resolver } = require('dns'); const { request, createServer } = require('http'); -const { setDefaultAutoSelectFamilyAttemptTimeout } = require('net'); // Test that happy eyeballs algorithm is properly implemented when using HTTP. -// Some of the windows machines in the CI need more time to establish connection -setDefaultAutoSelectFamilyAttemptTimeout(common.platformTimeout(common.isWindows ? 1500 : 250)); - function _lookup(resolver, hostname, options, cb) { resolver.resolve(hostname, 'ANY', (err, replies) => { assert.notStrictEqual(options.family, 4); diff --git a/test/parallel/test-http2-ping-settings-heapdump.js b/test/parallel/test-http2-ping-settings-heapdump.js index 775110c098..6023b5f6b8 100644 --- a/test/parallel/test-http2-ping-settings-heapdump.js +++ b/test/parallel/test-http2-ping-settings-heapdump.js @@ -11,14 +11,6 @@ const v8 = require('v8'); // after it is destroyed, either because they are detached from it or have been // destroyed themselves. -// We use an higher autoSelectFamilyAttemptTimeout in this test as the v8.getHeapSnapshot().resume() -// will slow the connection flow and we don't want the second connection attempt to start. -let autoSelectFamilyAttemptTimeout = common.platformTimeout(1000); -if (common.isWindows) { - // Some of the windows machines in the CI need more time to establish connection - autoSelectFamilyAttemptTimeout = common.platformTimeout(10000); -} - for (const variant of ['ping', 'settings']) { const server = http2.createServer(); server.on('session', common.mustCall((session) => { @@ -38,8 +30,7 @@ for (const variant of ['ping', 'settings']) { })); server.listen(0, common.mustCall(() => { - const client = http2.connect(`http://localhost:${server.address().port}`, { autoSelectFamilyAttemptTimeout }, - common.mustCall()); + const client = http2.connect(`http://localhost:${server.address().port}`, common.mustCall()); client.on('error', (err) => { // We destroy the session so it's possible to get ECONNRESET here. if (err.code !== 'ECONNRESET') diff --git a/test/parallel/test-https-autoselectfamily.js b/test/parallel/test-https-autoselectfamily.js index e9805939b5..cf7cc45010 100644 --- a/test/parallel/test-https-autoselectfamily.js +++ b/test/parallel/test-https-autoselectfamily.js @@ -13,7 +13,6 @@ const assert = require('assert'); const dgram = require('dgram'); const { Resolver } = require('dns'); const { request, createServer } = require('https'); -const { setDefaultAutoSelectFamilyAttemptTimeout } = require('net'); if (!common.hasCrypto) common.skip('missing crypto'); @@ -25,9 +24,6 @@ const options = { // Test that happy eyeballs algorithm is properly implemented when using HTTP. -// Some of the windows machines in the CI need more time to establish connection -setDefaultAutoSelectFamilyAttemptTimeout(common.platformTimeout(common.isWindows ? 1500 : 250)); - function _lookup(resolver, hostname, options, cb) { resolver.resolve(hostname, 'ANY', (err, replies) => { assert.notStrictEqual(options.family, 4); diff --git a/test/parallel/test-net-autoselectfamily-commandline-option.js b/test/parallel/test-net-autoselectfamily-commandline-option.js index 5554233741..5687d31b2e 100644 --- a/test/parallel/test-net-autoselectfamily-commandline-option.js +++ b/test/parallel/test-net-autoselectfamily-commandline-option.js @@ -1,6 +1,6 @@ 'use strict'; -// Flags: --enable-network-family-autoselection +// Flags: --no-network-family-autoselection const common = require('../common'); const { parseDNSPacket, writeDNSPacket } = require('../common/dns'); @@ -8,13 +8,10 @@ const { parseDNSPacket, writeDNSPacket } = require('../common/dns'); const assert = require('assert'); const dgram = require('dgram'); const { Resolver } = require('dns'); -const { createConnection, createServer, setDefaultAutoSelectFamilyAttemptTimeout } = require('net'); +const { createConnection, createServer } = require('net'); // Test that happy eyeballs algorithm can be enable from command line. -// Some of the windows machines in the CI need more time to establish connection -setDefaultAutoSelectFamilyAttemptTimeout(common.platformTimeout(common.isWindows ? 1500 : 250)); - function _lookup(resolver, hostname, options, cb) { resolver.resolve(hostname, 'ANY', (err, replies) => { assert.notStrictEqual(options.family, 4); @@ -62,7 +59,7 @@ function createDnsServer(ipv6Addr, ipv4Addr, cb) { }); } -// Test that IPV4 is reached if IPV6 is not reachable +// Test that IPV4 is NOT reached if IPV6 is not reachable and the option has been disabled via command line { createDnsServer('::1', '127.0.0.1', common.mustCall(function({ dnsServer, lookup }) { const ipv4Server = createServer((socket) => { @@ -77,28 +74,25 @@ function createDnsServer(ipv6Addr, ipv4Addr, cb) { const connection = createConnection({ host: 'example.org', - port: port, + port, lookup, }); - let response = ''; - connection.setEncoding('utf-8'); + connection.on('ready', common.mustNotCall()); + connection.on('error', common.mustCall((error) => { + assert.strictEqual(connection.autoSelectFamilyAttemptedAddresses, undefined); - connection.on('ready', common.mustCall(() => { - assert.deepStrictEqual(connection.autoSelectFamilyAttemptedAddresses, [`::1:${port}`, `127.0.0.1:${port}`]); - })); + if (common.hasIPv6) { + assert.strictEqual(error.code, 'ECONNREFUSED'); + assert.strictEqual(error.message, `connect ECONNREFUSED ::1:${port}`); + } else { + assert.strictEqual(error.code, 'EADDRNOTAVAIL'); + assert.strictEqual(error.message, `connect EADDRNOTAVAIL ::1:${port} - Local (:::0)`); + } - connection.on('data', (chunk) => { - response += chunk; - }); - - connection.on('end', common.mustCall(() => { - assert.strictEqual(response, 'response-ipv4'); ipv4Server.close(); dnsServer.close(); })); - - connection.write('request'); })); })); } diff --git a/test/parallel/test-net-autoselectfamilydefault.js b/test/parallel/test-net-autoselectfamily-default.js index be110a836a..2c87bf97df 100644 --- a/test/parallel/test-net-autoselectfamilydefault.js +++ b/test/parallel/test-net-autoselectfamily-default.js @@ -10,11 +10,7 @@ const { createConnection, createServer, setDefaultAutoSelectFamily } = require(' // Test that the default for happy eyeballs algorithm is properly respected. -let autoSelectFamilyAttemptTimeout = common.platformTimeout(250); -if (common.isWindows) { - // Some of the windows machines in the CI need more time to establish connection - autoSelectFamilyAttemptTimeout = common.platformTimeout(1500); -} +const autoSelectFamilyAttemptTimeout = common.defaultAutoSelectFamilyAttemptTimeout; function _lookup(resolver, hostname, options, cb) { resolver.resolve(hostname, 'ANY', (err, replies) => { diff --git a/test/parallel/test-net-autoselectfamily-ipv4first.js b/test/parallel/test-net-autoselectfamily-ipv4first.js index 794f7464a8..7c2e10213c 100644 --- a/test/parallel/test-net-autoselectfamily-ipv4first.js +++ b/test/parallel/test-net-autoselectfamily-ipv4first.js @@ -6,13 +6,10 @@ const { parseDNSPacket, writeDNSPacket } = require('../common/dns'); const assert = require('assert'); const dgram = require('dgram'); const { Resolver } = require('dns'); -const { createConnection, createServer, setDefaultAutoSelectFamilyAttemptTimeout } = require('net'); +const { createConnection, createServer } = require('net'); // Test that happy eyeballs algorithm is properly implemented when a A record is returned first. -// Some of the windows machines in the CI need more time to establish connection -setDefaultAutoSelectFamilyAttemptTimeout(common.platformTimeout(common.isWindows ? 1500 : 250)); - function _lookup(resolver, hostname, options, cb) { resolver.resolve(hostname, 'ANY', (err, replies) => { assert.notStrictEqual(options.family, 4); diff --git a/test/parallel/test-net-autoselectfamily.js b/test/parallel/test-net-autoselectfamily.js index 8deff52420..d95819000c 100644 --- a/test/parallel/test-net-autoselectfamily.js +++ b/test/parallel/test-net-autoselectfamily.js @@ -13,8 +13,8 @@ const { createConnection, createServer } = require('net'); // Purposely not using setDefaultAutoSelectFamilyAttemptTimeout here to test the // parameter is correctly used in options. // -// Some of the windows machines in the CI need more time to establish connection -const autoSelectFamilyAttemptTimeout = common.platformTimeout(common.isWindows ? 1500 : 250); +// Some of the machines in the CI need more time to establish connection +const autoSelectFamilyAttemptTimeout = common.defaultAutoSelectFamilyAttemptTimeout; function _lookup(resolver, hostname, options, cb) { resolver.resolve(hostname, 'ANY', (err, replies) => { diff --git a/test/parallel/test-tls-connect-hints-option.js b/test/parallel/test-tls-connect-hints-option.js index 4653e0a141..6abcf19402 100644 --- a/test/parallel/test-tls-connect-hints-option.js +++ b/test/parallel/test-tls-connect-hints-option.js @@ -25,7 +25,7 @@ tls.connect({ port: 42, lookup: common.mustCall((host, options) => { assert.strictEqual(host, 'localhost'); - assert.deepStrictEqual(options, { family: undefined, hints }); + assert.deepStrictEqual(options, { family: undefined, hints, all: true }); }), hints }); diff --git a/test/sequential/test-http-econnrefused.js b/test/sequential/test-http-econnrefused.js index 7f8c2cee56..4d0f7a174e 100644 --- a/test/sequential/test-http-econnrefused.js +++ b/test/sequential/test-http-econnrefused.js @@ -32,7 +32,6 @@ const common = require('../common'); const http = require('http'); const assert = require('assert'); - const server = http.createServer(function(req, res) { let body = ''; @@ -135,7 +134,10 @@ function ping() { console.log(`Error making ping req: ${error}`); hadError = true; assert.ok(!gotEnd); - afterPing(error.message); + + // Family autoselection might be skipped if only a single address is returned by DNS. + const actualError = Array.isArray(error.errors) ? error.errors[0] : error; + afterPing(actualError.message); }); } diff --git a/test/sequential/test-net-better-error-messages-port.js b/test/sequential/test-net-better-error-messages-port.js index c21427ee39..4f09b86d75 100644 --- a/test/sequential/test-net-better-error-messages-port.js +++ b/test/sequential/test-net-better-error-messages-port.js @@ -7,8 +7,11 @@ const c = net.createConnection(common.PORT); c.on('connect', common.mustNotCall()); -c.on('error', common.mustCall(function(e) { - assert.strictEqual(e.code, 'ECONNREFUSED'); - assert.strictEqual(e.port, common.PORT); - assert.match(e.address, /^(127\.0\.0\.1|::1)$/); +c.on('error', common.mustCall(function(error) { + // Family autoselection might be skipped if only a single address is returned by DNS. + const failedAttempt = Array.isArray(error.errors) ? error.errors[0] : error; + + assert.strictEqual(failedAttempt.code, 'ECONNREFUSED'); + assert.strictEqual(failedAttempt.port, common.PORT); + assert.match(failedAttempt.address, /^(127\.0\.0\.1|::1)$/); })); diff --git a/test/sequential/test-net-connect-econnrefused.js b/test/sequential/test-net-connect-econnrefused.js index 7dec16d232..c55a9ebe24 100644 --- a/test/sequential/test-net-connect-econnrefused.js +++ b/test/sequential/test-net-connect-econnrefused.js @@ -40,9 +40,12 @@ const server = net.createServer().listen(0, common.mustCall(() => { function pummel() { let pending; for (pending = 0; pending < ATTEMPTS_PER_ROUND; pending++) { - net.createConnection(port).on('error', function(err) { + net.createConnection({ port, autoSelectFamily: false }).on('error', function(error) { + // Family autoselection might be skipped if only a single address is returned by DNS. + const actualError = Array.isArray(error.errors) ? error.errors[0] : error; + console.log('pending', pending, 'rounds', rounds); - assert.strictEqual(err.code, 'ECONNREFUSED'); + assert.strictEqual(actualError.code, 'ECONNREFUSED'); if (--pending > 0) return; if (rounds === ROUNDS) return check(); rounds++; diff --git a/test/sequential/test-net-reconnect-error.js b/test/sequential/test-net-reconnect-error.js index 93d8f3673a..1fc26bb101 100644 --- a/test/sequential/test-net-reconnect-error.js +++ b/test/sequential/test-net-reconnect-error.js @@ -30,8 +30,11 @@ const c = net.createConnection(common.PORT); c.on('connect', common.mustNotCall('client should not have connected')); -c.on('error', common.mustCall((e) => { - assert.strictEqual(e.code, 'ECONNREFUSED'); +c.on('error', common.mustCall((error) => { + // Family autoselection might be skipped if only a single address is returned by DNS. + const actualError = Array.isArray(error.errors) ? error.errors[0] : error; + + assert.strictEqual(actualError.code, 'ECONNREFUSED'); }, N + 1)); c.on('close', common.mustCall(() => { |