diff options
Diffstat (limited to 'buildscripts/resmokelib')
-rw-r--r-- | buildscripts/resmokelib/testing/executor.py | 25 | ||||
-rw-r--r-- | buildscripts/resmokelib/testing/hooks/aggregate_metrics_background.py | 70 |
2 files changed, 84 insertions, 11 deletions
diff --git a/buildscripts/resmokelib/testing/executor.py b/buildscripts/resmokelib/testing/executor.py index 4fd76ea7093..c7e0beb24ce 100644 --- a/buildscripts/resmokelib/testing/executor.py +++ b/buildscripts/resmokelib/testing/executor.py @@ -43,6 +43,7 @@ class TestSuiteExecutor(object): # pylint: disable=too-many-instance-attributes else: self.fixture_config = fixture + print("hooks:", hooks) self.hooks_config = utils.default_if_none(hooks, []) self.test_config = utils.default_if_none(config, {}) @@ -53,7 +54,8 @@ class TestSuiteExecutor(object): # pylint: disable=too-many-instance-attributes self._suite = suite self.num_tests = len(suite.tests) * suite.options.num_repeat_tests - self.test_queue_logger = logging.loggers.new_testqueue_logger(suite.test_kind) + self.test_queue_logger = logging.loggers.new_testqueue_logger( + suite.test_kind) # Must be done after getting buildlogger configuration. self._jobs = self._create_jobs(self.num_tests) @@ -117,12 +119,14 @@ class TestSuiteExecutor(object): # pylint: disable=too-many-instance-attributes # still running if an Evergreen task were to time out from a hang/deadlock being # triggered. teardown_flag = threading.Event() if num_repeat_suites == 1 else None - (report, interrupted) = self._run_tests(test_queue, setup_flag, teardown_flag) + (report, interrupted) = self._run_tests( + test_queue, setup_flag, teardown_flag) self._suite.record_test_end(report) if setup_flag and setup_flag.is_set(): - self.logger.error("Setup of one of the job fixtures failed") + self.logger.error( + "Setup of one of the job fixtures failed") return_code = 2 return # Remove the setup flag once the first suite ran. @@ -137,7 +141,8 @@ class TestSuiteExecutor(object): # pylint: disable=too-many-instance-attributes sb = [] # String builder. self._suite.summarize_latest(sb) - self.logger.info("Summary of latest execution: %s", "\n ".join(sb)) + self.logger.info( + "Summary of latest execution: %s", "\n ".join(sb)) if not report.wasSuccessful(): return_code = 1 @@ -201,7 +206,8 @@ class TestSuiteExecutor(object): # pylint: disable=too-many-instance-attributes wait_secs = 2.0 self.logger.debug("Waiting for threads to complete") - timer = threading.Timer(wait_secs, self._log_timeout_warning, args=[wait_secs]) + timer = threading.Timer( + wait_secs, self._log_timeout_warning, args=[wait_secs]) timer.daemon = True timer.start() try: @@ -243,7 +249,8 @@ class TestSuiteExecutor(object): # pylint: disable=too-many-instance-attributes fixture_config = self.fixture_config.copy() fixture_class = fixture_config.pop("class") - fixture_logger = logging.loggers.new_fixture_logger(fixture_class, job_num) + fixture_logger = logging.loggers.new_fixture_logger( + fixture_class, job_num) return fixtures.make_fixture(fixture_class, fixture_logger, job_num, **fixture_config) @@ -257,7 +264,8 @@ class TestSuiteExecutor(object): # pylint: disable=too-many-instance-attributes hook_class = hook_config.pop("class") hook_logger = logging.loggers.new_hook_logger(hook_class, job_num) - hook = _hooks.make_hook(hook_class, hook_logger, fixture, **hook_config) + hook = _hooks.make_hook( + hook_class, hook_logger, fixture, **hook_config) hooks.append(hook) return hooks @@ -269,7 +277,8 @@ class TestSuiteExecutor(object): # pylint: disable=too-many-instance-attributes :param job_num: instance number of job being created. :return: Job instance. """ - job_logger = logging.loggers.new_job_logger(self._suite.test_kind, job_num) + job_logger = logging.loggers.new_job_logger( + self._suite.test_kind, job_num) fixture = self._make_fixture(job_num) hooks = self._make_hooks(fixture, job_num) diff --git a/buildscripts/resmokelib/testing/hooks/aggregate_metrics_background.py b/buildscripts/resmokelib/testing/hooks/aggregate_metrics_background.py index 73de9ee8d61..6816695f729 100644 --- a/buildscripts/resmokelib/testing/hooks/aggregate_metrics_background.py +++ b/buildscripts/resmokelib/testing/hooks/aggregate_metrics_background.py @@ -1,11 +1,75 @@ -"""Test hook for running the $operationMetrics stage in the background. +"""Test hook for running the $operationMetrics stage in the background. This hook runs every five seconds. """ +import os.path + +from buildscripts.resmokelib import errors from buildscripts.resmokelib.testing.hooks import jsfile -from buildscripts.resmokelib.testing.hooks.background_job import _BackgroundJob +from buildscripts.resmokelib.testing.hooks.background_job import _BackgroundJob, _ContinuousDynamicJSTestCase -class EnsureOperationMetricsAreAggregatedInBackground(jsfile.JSHook): +class AggregateResourceConsumptionMetricsInBackground(jsfile.JSHook): """A hook to run $operationMetrics stage in the background""" + + def __init__(self, hook_logger, fixture, shell_options=None): + """Initialize AggregateResourceConsumptionMetricsInBackground.""" + description = "Run background $operationMetrics on all mongods while a test is running" + js_filename = os.path.join( + "jstests", "hooks", "run_aggregate_metrics_background.js") + jsfile.JSHook.__init__(self, hook_logger, fixture, + js_filename, description, shell_options=shell_options) + self._background_job = None + + def before_suite(self, test_report): + """Start the background thread.""" + self._background_job = _BackgroundJob( + "AggregateResourceConsumptionMetricsInBackground") + self.logger.info("Starting the background aggregate metrics thread.") + self._background_job.start() + + def after_suite(self, test_report): + """Signal the background aggregate metrics thread to exit, and wait until it does.""" + if self._background_job is None: + return + + self.logger.info("Stopping the background aggregate metrics thread.") + self._background_job.stop() + + def before_test(self, test, test_report): + """Instruct the background aggregate metrics thread to run while 'test' is also running.""" + if self._background_job is None: + return + + hook_test_case = _ContinuousDynamicJSTestCase.create_before_test( + self.logger, test, self, self._js_filename, self._shell_options) + hook_test_case.configure(self.fixture) + + self.logger.info( + "Resuming the background aggregate metrics thread.") + self._background_job.resume(hook_test_case, test_report) + + def after_test(self, test, test_report): # noqa: D205,D400 + """Instruct the background aggregate metrics thread to stop running now that 'test' has + finished running. + """ + if self._background_job is None: + return + + self.logger.info( + "Pausing the background aggregate metrics thread.") + self._background_job.pause() + + if self._background_job.exc_info is not None: + if isinstance(self._background_job.exc_info[1], errors.TestFailure): + # If the mongo shell process running the JavaScript file exited with a non-zero + # return code, then we raise an errors.ServerFailure exception to cause resmoke.py's + # test execution to stop. + raise errors.ServerFailure( + self._background_job.exc_info[1].args[0]) + else: + self.logger.error( + "Encountered an error inside the background aggregate metrics thread.", + exc_info=self._background_job.exc_info) + raise self._background_job.exc_info[1] |