From 60c9cbf7b6ab033930003c0ef434d64136bddd02 Mon Sep 17 00:00:00 2001 From: Max Hirschhorn Date: Mon, 1 Oct 2018 18:31:03 -0400 Subject: 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. --- src/mongo/shell/servers_misc.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'src/mongo/shell/servers_misc.js') 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; + }; })(); /** -- cgit v1.2.1