diff options
author | Max Hirschhorn <max.hirschhorn@mongodb.com> | 2018-10-01 18:31:03 -0400 |
---|---|---|
committer | Max Hirschhorn <max.hirschhorn@mongodb.com> | 2018-10-01 18:31:03 -0400 |
commit | 60c9cbf7b6ab033930003c0ef434d64136bddd02 (patch) | |
tree | 314271c869db8928b3af07666f616ebbec6f63bf /src/mongo/shell/servers_misc.js | |
parent | 175f5e3c25ddba439b7d28254a4af5504aded0d8 (diff) | |
download | mongo-60c9cbf7b6ab033930003c0ef434d64136bddd02.tar.gz |
SERVER-31570 Stagger mongod/mongos ports +10 from mongobridge port.
Also introduces a resetAllocatedPorts() function so that tests which
allocate a large number of ports as part of starting many MongoDB
deployments can succeed despite the limited range of 250 - 20 = 230
ports given by resmoke.py to the job for the mongo shell.
Diffstat (limited to 'src/mongo/shell/servers_misc.js')
-rw-r--r-- | src/mongo/shell/servers_misc.js | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/src/mongo/shell/servers_misc.js b/src/mongo/shell/servers_misc.js index a83a9e507b4..c23b187d36a 100644 --- a/src/mongo/shell/servers_misc.js +++ b/src/mongo/shell/servers_misc.js @@ -65,14 +65,26 @@ ToolTest.prototype.runTool = function() { /** * Returns a port number that has not been given out to any other caller from the same mongo shell. */ -allocatePort = (function() { +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; + +(function() { // 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 // until after this has loaded. var maxPort; var nextPort; - return function() { + allocatePort = function() { // The default port was chosen in an attempt to have a large number of unassigned ports that // are also outside the ephemeral port range. nextPort = nextPort || jsTestOptions().minPort || 20000; @@ -83,6 +95,11 @@ allocatePort = (function() { } return nextPort++; }; + + resetAllocatedPorts = function() { + jsTest.log("Resetting the range of allocated ports"); + maxPort = nextPort = undefined; + }; })(); /** |