Skip to content

Commit

Permalink
SERVER-29008 Set TestData.numTestClients property in resmoke.py.
Browse files Browse the repository at this point in the history
Forwards the value for resmoke.py's --numClientsPerFixture command line
option to the mongo shell running the test. This enables the fuzzer to
know if there are concurrent clients running the test.
  • Loading branch information
visemet committed May 16, 2017
1 parent a4d2c52 commit 835a132
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
4 changes: 1 addition & 3 deletions buildscripts/resmokelib/core/programs.py
Expand Up @@ -119,8 +119,7 @@ def mongos_program(logger, executable=None, process_kwargs=None, **kwargs):
return _process.Process(logger, args, **process_kwargs)


def mongo_shell_program(logger, executable=None, filename=None, process_kwargs=None,
isMainTest=True, **kwargs):
def mongo_shell_program(logger, executable=None, filename=None, process_kwargs=None, **kwargs):
"""
Returns a Process instance that starts a mongo shell with arguments
constructed from 'kwargs'.
Expand Down Expand Up @@ -152,7 +151,6 @@ def mongo_shell_program(logger, executable=None, filename=None, process_kwargs=N
# Only use 'opt_default' if the property wasn't set in the YAML configuration.
test_data[opt_name] = opt_default

test_data["isMainTest"] = isMainTest
global_vars["TestData"] = test_data

# Pass setParameters for mongos and mongod through TestData. The setParameter parsing in
Expand Down
27 changes: 19 additions & 8 deletions buildscripts/resmokelib/testing/testcases.py
Expand Up @@ -359,9 +359,6 @@ def configure(self, fixture, num_clients=DEFAULT_CLIENT_NUM, *args, **kwargs):
test_data = global_vars.get("TestData", {}).copy()
test_data["minPort"] = core.network.PortAllocator.min_test_port(fixture.job_num)
test_data["maxPort"] = core.network.PortAllocator.max_test_port(fixture.job_num)
# Marks the main test when multiple test clients are run concurrently, to notify the test
# of any code that should only be run once. If there is only one client, it is the main one.
test_data["isMainTest"] = True

global_vars["TestData"] = test_data
self.shell_options["global_vars"] = global_vars
Expand Down Expand Up @@ -416,17 +413,31 @@ def run_test(self):
raise t._get_exception()

def _make_process(self, logger=None, thread_id=0):
# Since _make_process() is called by each thread, we make a shallow copy of the mongo shell
# options to avoid modifying the shared options for the JSTestCase.
shell_options = self.shell_options.copy()
global_vars = shell_options["global_vars"].copy()
test_data = global_vars["TestData"].copy()

# We set a property on TestData to mark the main test when multiple clients are going to run
# concurrently in case there is logic within the test that must execute only once. We also
# set a property on TestData to indicate how many clients are going to run the test so they
# can avoid executing certain logic when there may be other operations running concurrently.
is_main_test = thread_id == 0
test_data["isMainTest"] = is_main_test
test_data["numTestClients"] = self.num_clients

global_vars["TestData"] = test_data
shell_options["global_vars"] = global_vars

# If logger is none, it means that it's not running in a thread and thus logger should be
# set to self.logger.
logger = utils.default_if_none(logger, self.logger)
is_main_test = True
if thread_id > 0:
is_main_test = False

return core.programs.mongo_shell_program(logger,
executable=self.shell_executable,
filename=self.js_filename,
isMainTest=is_main_test,
**self.shell_options)
**shell_options)

def _run_test_in_thread(self, thread_id):
# Make a logger for each thread. When this method gets called self.logger has been
Expand Down

0 comments on commit 835a132

Please sign in to comment.