test: move hasMultiLocalhost to common/net

Given that `common/net` already exists and hasMultiLocalhost
is net specific, let's move it out of common/index to better
encapsulate and simplify common/index more

PR-URL: https://github.com/nodejs/node/pull/56716
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
James M Snell 2025-01-24 17:35:59 -08:00 committed by GitHub
parent 761de815c5
commit f07300cfa3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 19 additions and 21 deletions

View file

@ -238,12 +238,6 @@ Indicates if [internationalization][] is supported.
Indicates whether `IPv6` is supported on this platform.
### `hasMultiLocalhost`
* [\<boolean>][<boolean>]
Indicates if there are multiple localhosts available.
### `inFreeBSDJail`
* [\<boolean>][<boolean>]

View file

@ -489,15 +489,6 @@ function _mustCallInner(fn, criteria = 1, field) {
return _return;
}
function hasMultiLocalhost() {
const { internalBinding } = require('internal/test/binding');
const { TCP, constants: TCPConstants } = internalBinding('tcp_wrap');
const t = new TCP(TCPConstants.SOCKET);
const ret = t.bind('127.0.0.2', 0);
t.close();
return ret === 0;
}
function skipIfEslintMissing() {
if (!fs.existsSync(
path.join(__dirname, '..', '..', 'tools', 'eslint', 'node_modules', 'eslint'),
@ -965,7 +956,6 @@ const common = {
hasIntl,
hasCrypto,
hasQuic,
hasMultiLocalhost,
invalidArgTypeHelper,
isAlive,
isASan,

View file

@ -20,7 +20,6 @@ const {
hasCrypto,
hasIntl,
hasIPv6,
hasMultiLocalhost,
isAIX,
isAlive,
isDumbTerminal,
@ -75,7 +74,6 @@ export {
hasCrypto,
hasIntl,
hasIPv6,
hasMultiLocalhost,
isAIX,
isAlive,
isDumbTerminal,

View file

@ -17,7 +17,17 @@ function checkSupportReusePort() {
});
}
function hasMultiLocalhost() {
const { internalBinding } = require('internal/test/binding');
const { TCP, constants: TCPConstants } = internalBinding('tcp_wrap');
const t = new TCP(TCPConstants.SOCKET);
const ret = t.bind('127.0.0.2', 0);
t.close();
return ret === 0;
}
module.exports = {
checkSupportReusePort,
hasMultiLocalhost,
options,
};

View file

@ -22,8 +22,10 @@
// Flags: --expose-internals
'use strict';
const common = require('../common');
if (!common.hasMultiLocalhost())
const { hasMultiLocalhost } = require('../common/net');
if (!hasMultiLocalhost()) {
common.skip('platform-specific test.');
}
const http = require('http');
const assert = require('assert');

View file

@ -4,8 +4,10 @@ const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
if (!common.hasMultiLocalhost())
const { hasMultiLocalhost } = require('../common/net');
if (!hasMultiLocalhost()) {
common.skip('platform-specific test.');
}
const http2 = require('http2');
const assert = require('assert');

View file

@ -25,8 +25,10 @@ const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
if (!common.hasMultiLocalhost())
const { hasMultiLocalhost } = require('../common/net');
if (!hasMultiLocalhost()) {
common.skip('platform-specific test.');
}
const fixtures = require('../common/fixtures');
const assert = require('assert');