mirror of https://github.com/mongodb/mongo
SERVER-105597: Make servers_misc.js a module (#38494)
GitOrigin-RevId: 2c3ef1ed3cc219669a6a548cc3e858885ea97999
This commit is contained in:
parent
276d937703
commit
a6f2fa1f90
|
|
@ -96,7 +96,7 @@ export default [
|
||||||
startMongoProgram: true,
|
startMongoProgram: true,
|
||||||
startMongoProgramNoConnect: true,
|
startMongoProgramNoConnect: true,
|
||||||
|
|
||||||
// src/mongo/shell/servers_misc.d.ts
|
// src/mongo/shell/servers_misc_global.js
|
||||||
ToolTest: true,
|
ToolTest: true,
|
||||||
allocatePort: true,
|
allocatePort: true,
|
||||||
allocatePorts: true,
|
allocatePorts: true,
|
||||||
|
|
|
||||||
|
|
@ -323,6 +323,7 @@ MONGO_SERVER_CPP_JS_FILES = [
|
||||||
"keyvault.js",
|
"keyvault.js",
|
||||||
"servers.js",
|
"servers.js",
|
||||||
"servers_misc.js",
|
"servers_misc.js",
|
||||||
|
"servers_misc_global.js",
|
||||||
]
|
]
|
||||||
|
|
||||||
render_template(
|
render_template(
|
||||||
|
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
// type declarations for servers_misc.js
|
|
||||||
|
|
||||||
declare function ToolTest()
|
|
||||||
declare function allocatePort()
|
|
||||||
declare function allocatePorts()
|
|
||||||
declare function resetAllocatedPorts()
|
|
||||||
declare function startParallelShell()
|
|
||||||
declare var testingReplication
|
|
||||||
declare function uncheckedParallelShellPidsString()
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
ToolTest = function(name, extraOptions) {
|
function ToolTest(name, extraOptions) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.options = extraOptions;
|
this.options = extraOptions;
|
||||||
this.port = allocatePort();
|
this.port = allocatePort();
|
||||||
|
|
@ -62,33 +62,18 @@ ToolTest.prototype.runTool = function() {
|
||||||
return runMongoProgram.apply(null, a);
|
return runMongoProgram.apply(null, a);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a port number that has not been given out to any other caller from the same mongo shell.
|
|
||||||
*/
|
|
||||||
var allocatePort;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Resets the range of ports which have already been given out to callers of allocatePort().
|
|
||||||
*
|
|
||||||
* This function can be used to allow a test to allocate a large number of ports as part of starting
|
|
||||||
* many MongoDB deployments without worrying about hitting the configured maximum. Callers of this
|
|
||||||
* function should take care to ensure MongoDB deployments started earlier have been terminated and
|
|
||||||
* won't be reused.
|
|
||||||
*/
|
|
||||||
var resetAllocatedPorts;
|
|
||||||
|
|
||||||
var uncheckedParallelShellPids;
|
var uncheckedParallelShellPids;
|
||||||
|
|
||||||
var startParallelShell;
|
|
||||||
|
|
||||||
(function() {
|
|
||||||
// Defer initializing these variables until the first call, as TestData attributes may be
|
// Defer initializing these variables until the first call, as TestData attributes may be
|
||||||
// initialized as part of the --eval argument (e.g. by resmoke.py), which will not be evaluated
|
// initialized as part of the --eval argument (e.g. by resmoke.py), which will not be evaluated
|
||||||
// until after this has loaded.
|
// until after this has loaded.
|
||||||
var maxPort;
|
var maxPort;
|
||||||
var nextPort;
|
var nextPort;
|
||||||
|
|
||||||
allocatePort = function() {
|
/**
|
||||||
|
* Returns a port number that has not been given out to any other caller from the same mongo shell.
|
||||||
|
*/
|
||||||
|
function allocatePort() {
|
||||||
// The default port was chosen in an attempt to have a large number of unassigned ports that
|
// The default port was chosen in an attempt to have a large number of unassigned ports that
|
||||||
// are also outside the ephemeral port range.
|
// are also outside the ephemeral port range.
|
||||||
nextPort = nextPort || jsTestOptions().minPort || 20000;
|
nextPort = nextPort || jsTestOptions().minPort || 20000;
|
||||||
|
|
@ -100,17 +85,25 @@ allocatePort = function() {
|
||||||
return nextPort++;
|
return nextPort++;
|
||||||
};
|
};
|
||||||
|
|
||||||
resetAllocatedPorts = function() {
|
/**
|
||||||
|
* Resets the range of ports which have already been given out to callers of allocatePort().
|
||||||
|
*
|
||||||
|
* This function can be used to allow a test to allocate a large number of ports as part of starting
|
||||||
|
* many MongoDB deployments without worrying about hitting the configured maximum. Callers of this
|
||||||
|
* function should take care to ensure MongoDB deployments started earlier have been terminated and
|
||||||
|
* won't be reused.
|
||||||
|
*/
|
||||||
|
function resetAllocatedPorts() {
|
||||||
jsTest.log("Resetting the range of allocated ports");
|
jsTest.log("Resetting the range of allocated ports");
|
||||||
maxPort = nextPort = undefined;
|
maxPort = nextPort = undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
var parallelShellPids = [];
|
var parallelShellPids = [];
|
||||||
uncheckedParallelShellPidsString = function() {
|
function uncheckedParallelShellPidsString() {
|
||||||
return parallelShellPids.join(", ");
|
return parallelShellPids.join(", ");
|
||||||
};
|
};
|
||||||
|
|
||||||
startParallelShell = function(jsCode, port, noConnect, ...optionArgs) {
|
function startParallelShell(jsCode, port, noConnect, ...optionArgs) {
|
||||||
var shellPath = MongoRunner.getMongoShellPath();
|
var shellPath = MongoRunner.getMongoShellPath();
|
||||||
var args = [shellPath];
|
var args = [shellPath];
|
||||||
|
|
||||||
|
|
@ -189,13 +182,12 @@ startParallelShell = function(jsCode, port, noConnect, ...optionArgs) {
|
||||||
return exitCode;
|
return exitCode;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
})();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list of 'numPorts' port numbers that have not been given out to any other caller from
|
* Returns a list of 'numPorts' port numbers that have not been given out to any other caller from
|
||||||
* the same mongo shell.
|
* the same mongo shell.
|
||||||
*/
|
*/
|
||||||
allocatePorts = function(numPorts) {
|
function allocatePorts(numPorts) {
|
||||||
var ports = [];
|
var ports = [];
|
||||||
for (var i = 0; i < numPorts; i++) {
|
for (var i = 0; i < numPorts; i++) {
|
||||||
ports.push(allocatePort());
|
ports.push(allocatePort());
|
||||||
|
|
@ -205,3 +197,13 @@ allocatePorts = function(numPorts) {
|
||||||
};
|
};
|
||||||
|
|
||||||
var testingReplication = false;
|
var testingReplication = false;
|
||||||
|
|
||||||
|
export {
|
||||||
|
ToolTest,
|
||||||
|
allocatePort,
|
||||||
|
allocatePorts,
|
||||||
|
resetAllocatedPorts,
|
||||||
|
startParallelShell,
|
||||||
|
testingReplication,
|
||||||
|
uncheckedParallelShellPidsString,
|
||||||
|
};
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
// Populate global variables from modules for backwards compatibility
|
||||||
|
|
||||||
|
import {
|
||||||
|
allocatePort,
|
||||||
|
allocatePorts,
|
||||||
|
resetAllocatedPorts,
|
||||||
|
startParallelShell,
|
||||||
|
testingReplication,
|
||||||
|
ToolTest,
|
||||||
|
uncheckedParallelShellPidsString,
|
||||||
|
} from "src/mongo/shell/servers_misc.js";
|
||||||
|
|
||||||
|
globalThis.ToolTest = ToolTest;
|
||||||
|
globalThis.allocatePort = allocatePort;
|
||||||
|
globalThis.allocatePorts = allocatePorts;
|
||||||
|
globalThis.resetAllocatedPorts = resetAllocatedPorts;
|
||||||
|
globalThis.startParallelShell = startParallelShell;
|
||||||
|
globalThis.testingReplication = testingReplication;
|
||||||
|
globalThis.uncheckedParallelShellPidsString = uncheckedParallelShellPidsString;
|
||||||
|
|
@ -163,6 +163,7 @@ extern const JSFile feature_compatibility_version;
|
||||||
extern const JSFile feature_compatibility_version_global;
|
extern const JSFile feature_compatibility_version_global;
|
||||||
extern const JSFile servers;
|
extern const JSFile servers;
|
||||||
extern const JSFile servers_misc;
|
extern const JSFile servers_misc;
|
||||||
|
extern const JSFile servers_misc_global;
|
||||||
} // namespace JSFiles
|
} // namespace JSFiles
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
@ -1234,15 +1235,16 @@ void initScope(Scope& scope) {
|
||||||
scope.execSetup(JSFiles::bridge);
|
scope.execSetup(JSFiles::bridge);
|
||||||
scope.execSetup(JSFiles::data_consistency_checker);
|
scope.execSetup(JSFiles::data_consistency_checker);
|
||||||
scope.execSetup(JSFiles::feature_compatibility_version);
|
scope.execSetup(JSFiles::feature_compatibility_version);
|
||||||
|
scope.execSetup(JSFiles::servers_misc);
|
||||||
|
|
||||||
// globals
|
// globals
|
||||||
scope.execSetup(JSFiles::bridge_global);
|
scope.execSetup(JSFiles::bridge_global);
|
||||||
scope.execSetup(JSFiles::data_consistency_checker_global);
|
scope.execSetup(JSFiles::data_consistency_checker_global);
|
||||||
scope.execSetup(JSFiles::feature_compatibility_version_global);
|
scope.execSetup(JSFiles::feature_compatibility_version_global);
|
||||||
|
scope.execSetup(JSFiles::servers_misc_global);
|
||||||
|
|
||||||
// scripts
|
// scripts
|
||||||
scope.execSetup(JSFiles::servers);
|
scope.execSetup(JSFiles::servers);
|
||||||
scope.execSetup(JSFiles::servers_misc);
|
|
||||||
|
|
||||||
initializeEnterpriseScope(scope);
|
initializeEnterpriseScope(scope);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue