diff options
author | Max Hirschhorn <max.hirschhorn@mongodb.com> | 2017-10-18 01:45:51 -0400 |
---|---|---|
committer | Max Hirschhorn <max.hirschhorn@mongodb.com> | 2017-10-18 01:45:51 -0400 |
commit | 046a5a01c1bc6eeb05852bed9981cbc457802a00 (patch) | |
tree | f7a65cb458c422dc7c7451348f1f029f5c95f663 /buildscripts/resmoke.py | |
parent | fb3b2eb0ac9c92c3e9a541a8e25aaa542d05e42f (diff) | |
download | mongo-046a5a01c1bc6eeb05852bed9981cbc457802a00.tar.gz |
SERVER-31470 Move "run tests" logic into evergreen_run_tests.py.
Diffstat (limited to 'buildscripts/resmoke.py')
-rwxr-xr-x | buildscripts/resmoke.py | 153 |
1 files changed, 91 insertions, 62 deletions
diff --git a/buildscripts/resmoke.py b/buildscripts/resmoke.py index 6e361a1ce7b..1d5bc7be694 100755 --- a/buildscripts/resmoke.py +++ b/buildscripts/resmoke.py @@ -30,14 +30,14 @@ def _execute_suite(suite): if resmokelib.config.SHUFFLE: logger.info("Shuffling order of tests for %ss in suite %s. The seed is %d.", - suite.test_kind, suite.get_name(), resmokelib.config.RANDOM_SEED) + suite.test_kind, suite.get_display_name(), resmokelib.config.RANDOM_SEED) random.seed(resmokelib.config.RANDOM_SEED) random.shuffle(suite.tests) if resmokelib.config.DRY_RUN == "tests": sb = [] sb.append("Tests that would be run for %ss in suite %s:" - % (suite.test_kind, suite.get_name())) + % (suite.test_kind, suite.get_display_name())) if len(suite.tests) > 0: for test in suite.tests: sb.append(test) @@ -48,25 +48,29 @@ def _execute_suite(suite): # Set a successful return code on the test suite because we want to output the tests # that would get run by any other suites the user specified. suite.return_code = 0 - return True + return False if len(suite.tests) == 0: logger.info("Skipping %ss, no tests to run", suite.test_kind) - return True + + # Set a successful return code on the test suite because we want to output the tests + # that would get run by any other suites the user specified. + suite.return_code = 0 + return False executor_config = suite.get_executor_config() executor = resmokelib.testing.executor.TestSuiteExecutor(logger, suite, **executor_config) try: executor.run() - if resmokelib.config.FAIL_FAST and suite.return_code != 0: + if suite.options.fail_fast and suite.return_code != 0: return False except resmokelib.errors.UserInterrupt: suite.return_code = 130 # Simulate SIGINT as exit code. return True except: logger.exception("Encountered an error when running %ss of suite %s.", - suite.test_kind, suite.get_name()) + suite.test_kind, suite.get_display_name()) suite.return_code = 2 return False @@ -90,7 +94,7 @@ def _dump_suite_config(suite, logging_config): """ sb = [] - sb.append("YAML configuration of suite %s" % (suite.get_name())) + sb.append("YAML configuration of suite %s" % (suite.get_display_name())) sb.append(resmokelib.utils.dump_yaml({"test_kind": suite.get_test_kind_config()})) sb.append("") sb.append(resmokelib.utils.dump_yaml({"selector": suite.get_selector_config()})) @@ -120,75 +124,100 @@ def _list_suites_and_exit(logger, exit_code=0): logger.info("Suites available to execute:\n%s", "\n".join(suite_names)) sys.exit(exit_code) -def main(): - start_time = time.time() - values, args = resmokelib.parser.parse_command_line() +class Main(object): + """ + A class for executing potentially multiple resmoke.py test suites. + """ + + def __init__(self): + """ + Initializes the Main instance by parsing the command line arguments. + """ + + self.__start_time = time.time() - logging_config = resmokelib.parser.get_logging_config(values) - resmokelib.logging.loggers.configure_loggers(logging_config) - resmokelib.logging.flush.start_thread() + values, args = resmokelib.parser.parse_command_line() + self.__values = values + self.__args = args - resmokelib.parser.update_config_vars(values) + def _get_suites(self): + """ + Returns a list of resmokelib.testing.suite.Suite instances to execute. + """ - exec_logger = resmokelib.logging.loggers.EXECUTOR_LOGGER - resmoke_logger = exec_logger.new_resmoke_logger() + return resmokelib.parser.get_suites(self.__values, self.__args) - if values.list_suites: - _list_suites_and_exit(resmoke_logger) + def run(self): + """ + Executes the list of resmokelib.testing.suite.Suite instances returned by _get_suites(). + """ - # Log the command line arguments specified to resmoke.py to make it easier to re-run the - # resmoke.py invocation used by an Evergreen task. - resmoke_logger.info("resmoke.py invocation: %s", " ".join(sys.argv)) + logging_config = resmokelib.parser.get_logging_config(self.__values) + resmokelib.logging.loggers.configure_loggers(logging_config) + resmokelib.logging.flush.start_thread() - interrupted = False - try: - suites = resmokelib.parser.get_suites(values, args) - except resmokelib.errors.SuiteNotFound as err: - resmoke_logger.error("Failed to parse YAML suite definition: %s", str(err)) - _list_suites_and_exit(resmoke_logger, exit_code=1) - - # Register a signal handler or Windows event object so we can write the report file if the task - # times out. - resmokelib.sighandler.register(resmoke_logger, suites, start_time) - - # Run the suite finder after the test suite parsing is complete. - if values.find_suites: - suites_by_test = find_suites_by_test(suites) - for test in sorted(suites_by_test): - suite_names = suites_by_test[test] - resmoke_logger.info("%s will be run by the following suite(s): %s", test, suite_names) - sys.exit(0) + resmokelib.parser.update_config_vars(self.__values) - try: - for suite in suites: - resmoke_logger.info(_dump_suite_config(suite, logging_config)) + exec_logger = resmokelib.logging.loggers.EXECUTOR_LOGGER + resmoke_logger = exec_logger.new_resmoke_logger() + + if self.__values.list_suites: + _list_suites_and_exit(resmoke_logger) + + # Log the command line arguments specified to resmoke.py to make it easier to re-run the + # resmoke.py invocation used by an Evergreen task. + resmoke_logger.info("resmoke.py invocation: %s", " ".join(sys.argv)) + + interrupted = False + try: + suites = self._get_suites() + except resmokelib.errors.SuiteNotFound as err: + resmoke_logger.error("Failed to parse YAML suite definition: %s", str(err)) + _list_suites_and_exit(resmoke_logger, exit_code=1) + + # Register a signal handler or Windows event object so we can write the report file if the + # task times out. + resmokelib.sighandler.register(resmoke_logger, suites, self.__start_time) + + # Run the suite finder after the test suite parsing is complete. + if self.__values.find_suites: + suites_by_test = find_suites_by_test(suites) + for test in sorted(suites_by_test): + suite_names = suites_by_test[test] + resmoke_logger.info("%s will be run by the following suite(s): %s", + test, suite_names) + sys.exit(0) + + try: + for suite in suites: + resmoke_logger.info(_dump_suite_config(suite, logging_config)) - suite.record_suite_start() - interrupted = _execute_suite(suite) - suite.record_suite_end() + suite.record_suite_start() + interrupted = _execute_suite(suite) + suite.record_suite_end() - resmoke_logger.info("=" * 80) - resmoke_logger.info("Summary of %s suite: %s", - suite.get_name(), _summarize_suite(suite)) + resmoke_logger.info("=" * 80) + resmoke_logger.info("Summary of %s suite: %s", + suite.get_display_name(), _summarize_suite(suite)) - if interrupted or (resmokelib.config.FAIL_FAST and suite.return_code != 0): - time_taken = time.time() - start_time - _log_summary(resmoke_logger, suites, time_taken) - sys.exit(suite.return_code) + if interrupted or (suite.options.fail_fast and suite.return_code != 0): + time_taken = time.time() - self.__start_time + _log_summary(resmoke_logger, suites, time_taken) + sys.exit(suite.return_code) - time_taken = time.time() - start_time - _log_summary(resmoke_logger, suites, time_taken) + time_taken = time.time() - self.__start_time + _log_summary(resmoke_logger, suites, time_taken) - # Exit with a nonzero code if any of the suites failed. - exit_code = max(suite.return_code for suite in suites) - sys.exit(exit_code) - finally: - if not interrupted: - resmokelib.logging.flush.stop_thread() + # Exit with a nonzero code if any of the suites failed. + exit_code = max(suite.return_code for suite in suites) + sys.exit(exit_code) + finally: + if not interrupted: + resmokelib.logging.flush.stop_thread() - resmokelib.reportfile.write(suites) + resmokelib.reportfile.write(suites) if __name__ == "__main__": - main() + Main().run() |