Skip to content

Commit

Permalink
test: move hasMultiLocalhost to common/net
Browse files Browse the repository at this point in the history
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: #56716
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
  • Loading branch information
jasnell authored Jan 25, 2025
1 parent 761de81 commit f07300c
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 21 deletions.
6 changes: 0 additions & 6 deletions test/common/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>]
Expand Down
10 changes: 0 additions & 10 deletions test/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down Expand Up @@ -965,7 +956,6 @@ const common = {
hasIntl,
hasCrypto,
hasQuic,
hasMultiLocalhost,
invalidArgTypeHelper,
isAlive,
isASan,
Expand Down
2 changes: 0 additions & 2 deletions test/common/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const {
hasCrypto,
hasIntl,
hasIPv6,
hasMultiLocalhost,
isAIX,
isAlive,
isDumbTerminal,
Expand Down Expand Up @@ -75,7 +74,6 @@ export {
hasCrypto,
hasIntl,
hasIPv6,
hasMultiLocalhost,
isAIX,
isAlive,
isDumbTerminal,
Expand Down
10 changes: 10 additions & 0 deletions test/common/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
4 changes: 3 additions & 1 deletion test/parallel/test-http-localaddress.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
4 changes: 3 additions & 1 deletion test/parallel/test-http2-connect-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
4 changes: 3 additions & 1 deletion test/parallel/test-https-localaddress.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit f07300c

Please sign in to comment.