def main(): """Ducktape entry point. This contains top level logic for ducktape command-line program which does the following: Discover tests Initialize cluster for distributed services Run tests Report a summary of all results """ args = parse_args() # Make .ducktape directory where metadata such as the last used session_id is stored if not os.path.isdir(ConsoleConfig.METADATA_DIR): os.makedirs(ConsoleConfig.METADATA_DIR) # Generate a shared 'global' identifier for this test run and create the directory # in which all test results will be stored session_id = generate_session_id(ConsoleConfig.SESSION_ID_FILE) results_dir = generate_results_dir(session_id) setup_results_directory(results_dir, session_id) session_context = SessionContext(session_id, results_dir, cluster=None, args=args) # Discover and load tests to be run extend_import_paths(args.test_path) loader = TestLoader(session_context) try: test_classes = loader.discover(args.test_path) except LoaderException as e: print "Failed while trying to discover tests: {}".format(e) sys.exit(1) if args.collect_only: print test_classes sys.exit(0) # Initializing the cluster is slow, so do so only if # tests are sure to be run session_context.cluster = VagrantCluster() # Run the tests runner = SerialTestRunner(session_context, test_classes) test_results = runner.run_all_tests() # Report results # TODO command-line hook for type of reporter reporter = SimpleStdoutReporter(test_results) reporter.report() reporter = SimpleFileReporter(test_results) reporter.report() # Generate HTML reporter reporter = HTMLReporter(test_results) reporter.report() if not test_results.get_aggregate_success(): sys.exit(1)
def check_simple_run(self): """Check expected behavior when running a single test.""" mock_cluster = MagicMock() mock_cluster.__len__.return_value = 100000 # big enough to run the test! session_context = tests.ducktape_mock.session_context(mock_cluster) test_context = TestContext(session_context, module=None, cls=TestThingy, function=TestThingy.test_pi) runner = SerialTestRunner(session_context, [test_context]) runner.log = Mock() results = runner.run_all_tests() assert len(results) == 1 assert results.num_failed() == 0 assert results.num_passed() == 1 assert results[0].data == {"data": 3.14159}
def check_insufficient_cluster_resources(self): """The test runner should behave sensibly when the cluster is too small to run a given test.""" mock_cluster = MagicMock() mock_cluster.__len__.return_value = 1 session_context = tests.ducktape_mock.session_context(mock_cluster) test_context = TestContext(session_context, module=None, cls=TestThingy, function=TestThingy.test_pi) runner = SerialTestRunner(session_context, [test_context]) runner.log = Mock() # Even though the cluster is too small, the test runner should this handle gracefully without raising an error results = runner.run_all_tests() assert len(results) == 1 assert results.num_failed() == 1 assert results.num_passed() == 0
def check_simple_run(self): """Check expected behavior when running a single test.""" mock_cluster = LocalhostCluster() session_context = tests.ducktape_mock.session_context(mock_cluster) test_methods = [TestThingy.test_pi, TestThingy.test_ignore1, TestThingy.test_ignore2] ctx_list = [] for f in test_methods: ctx_list.extend( MarkedFunctionExpander(session_context=session_context, cls=TestThingy, function=f).expand() ) runner = SerialTestRunner(session_context, ctx_list) runner.log = Mock() results = runner.run_all_tests() assert len(results) == 3 assert results.num_failed == 0 assert results.num_passed == 1 assert results.num_ignored == 2 assert results[0].data == {"data": 3.14159}
def main(): """Ducktape entry point. This contains top level logic for ducktape command-line program which does the following: Discover tests Initialize cluster for distributed services Run tests Report a summary of all results """ args_dict = parse_args(sys.argv[1:]) parameters = None if args_dict["parameters"]: try: parameters = json.loads(args_dict["parameters"]) except ValueError as e: print "parameters are not valid json: " + str(e.message) sys.exit(1) args_dict["globals"] = get_user_defined_globals(args_dict.get("globals")) # Make .ducktape directory where metadata such as the last used session_id is stored if not os.path.isdir(ConsoleDefaults.METADATA_DIR): os.makedirs(ConsoleDefaults.METADATA_DIR) # Generate a shared 'global' identifier for this test run and create the directory # in which all test results will be stored session_id = generate_session_id(ConsoleDefaults.SESSION_ID_FILE) results_dir = generate_results_dir(args_dict["results_root"], session_id) setup_results_directory(results_dir) session_context = SessionContext(session_id=session_id, results_dir=results_dir, **args_dict) for k, v in args_dict.iteritems(): session_context.logger.debug("Configuration: %s=%s", k, v) # Discover and load tests to be run extend_import_paths(args_dict["test_path"]) loader = TestLoader(session_context, parameters) try: tests = loader.discover(args_dict["test_path"]) except LoaderException as e: print "Failed while trying to discover tests: {}".format(e) sys.exit(1) if args_dict["collect_only"]: print "Collected %d tests:" % len(tests) for test in tests: print " " + str(test) sys.exit(0) # Initializing the cluster is slow, so do so only if # tests are sure to be run try: (cluster_mod_name, cluster_class_name) = args_dict["cluster"].rsplit('.', 1) cluster_mod = importlib.import_module(cluster_mod_name) cluster_class = getattr(cluster_mod, cluster_class_name) session_context.cluster = cluster_class(cluster_file=args_dict["cluster_file"]) except: print "Failed to load cluster: ", str(sys.exc_info()[0]) print traceback.format_exc(limit=16) sys.exit(1) # Run the tests runner = SerialTestRunner(session_context, tests) test_results = runner.run_all_tests() # Report results reporter = SimpleStdoutSummaryReporter(test_results) reporter.report() reporter = SimpleFileSummaryReporter(test_results) reporter.report() # Generate HTML reporter reporter = HTMLSummaryReporter(test_results) reporter.report() update_latest_symlink(args_dict["results_root"], results_dir) if not test_results.get_aggregate_success(): sys.exit(1)
def main(): """Ducktape entry point. This contains top level logic for ducktape command-line program which does the following: Discover tests Initialize cluster for distributed services Run tests Report a summary of all results """ args = parse_args() if args.version: print ducktape_version() sys.exit(0) # Make .ducktape directory where metadata such as the last used session_id is stored if not os.path.isdir(ConsoleConfig.METADATA_DIR): os.makedirs(ConsoleConfig.METADATA_DIR) # Generate a shared 'global' identifier for this test run and create the directory # in which all test results will be stored session_id = generate_session_id(ConsoleConfig.SESSION_ID_FILE) results_dir = generate_results_dir(args.results_root, session_id) setup_results_directory(args.results_root, results_dir) session_context = SessionContext(session_id, results_dir, cluster=None, args=args) for k, v in vars(args).iteritems(): session_context.logger.debug("Configuration: %s=%s", k, v) # Discover and load tests to be run extend_import_paths(args.test_path) loader = TestLoader(session_context) try: tests = loader.discover(args.test_path) except LoaderException as e: print "Failed while trying to discover tests: {}".format(e) sys.exit(1) if args.collect_only: print "Collected %d tests:" % len(tests) for test in tests: print " " + str(test) sys.exit(0) # Initializing the cluster is slow, so do so only if # tests are sure to be run try: (cluster_mod_name, cluster_class_name) = args.cluster.rsplit('.', 1) cluster_mod = importlib.import_module(cluster_mod_name) cluster_class = getattr(cluster_mod, cluster_class_name) session_context.cluster = cluster_class() except: print "Failed to load cluster: ", str(sys.exc_info()[0]) print traceback.format_exc(limit=16) sys.exit(1) # Run the tests runner = SerialTestRunner(session_context, tests) test_results = runner.run_all_tests() # Report results # TODO command-line hook for type of reporter reporter = SimpleStdoutSummaryReporter(test_results) reporter.report() reporter = SimpleFileSummaryReporter(test_results) reporter.report() # Generate HTML reporter reporter = HTMLSummaryReporter(test_results) reporter.report() if not test_results.get_aggregate_success(): sys.exit(1)
def main(): """Ducktape entry point. This contains top level logic for ducktape command-line program which does the following: Discover tests Initialize cluster for distributed services Run tests Report a summary of all results """ args_dict = parse_args(sys.argv[1:]) parameters = None if args_dict["parameters"]: try: parameters = json.loads(args_dict["parameters"]) except ValueError as e: print "parameters are not valid json: " + str(e.message) sys.exit(1) args_dict["globals"] = get_user_defined_globals(args_dict.get("globals")) # Make .ducktape directory where metadata such as the last used session_id is stored if not os.path.isdir(ConsoleDefaults.METADATA_DIR): os.makedirs(ConsoleDefaults.METADATA_DIR) # Generate a shared 'global' identifier for this test run and create the directory # in which all test results will be stored session_id = generate_session_id(ConsoleDefaults.SESSION_ID_FILE) results_dir = generate_results_dir(args_dict["results_root"], session_id) setup_results_directory(results_dir) session_context = SessionContext(session_id=session_id, results_dir=results_dir, **args_dict) for k, v in args_dict.iteritems(): session_context.logger.debug("Configuration: %s=%s", k, v) # Discover and load tests to be run extend_import_paths(args_dict["test_path"]) loader = TestLoader(session_context, parameters) try: tests = loader.discover(args_dict["test_path"]) except LoaderException as e: print "Failed while trying to discover tests: {}".format(e) sys.exit(1) if args_dict["collect_only"]: print "Collected %d tests:" % len(tests) for test in tests: print " " + str(test) sys.exit(0) # Initializing the cluster is slow, so do so only if # tests are sure to be run try: (cluster_mod_name, cluster_class_name) = args_dict["cluster"].rsplit('.', 1) cluster_mod = importlib.import_module(cluster_mod_name) cluster_class = getattr(cluster_mod, cluster_class_name) session_context.cluster = cluster_class( cluster_file=args_dict["cluster_file"]) except: print "Failed to load cluster: ", str(sys.exc_info()[0]) print traceback.format_exc(limit=16) sys.exit(1) # Run the tests runner = SerialTestRunner(session_context, tests) test_results = runner.run_all_tests() # Report results reporter = SimpleStdoutSummaryReporter(test_results) reporter.report() reporter = SimpleFileSummaryReporter(test_results) reporter.report() # Generate HTML reporter reporter = HTMLSummaryReporter(test_results) reporter.report() update_latest_symlink(args_dict["results_root"], results_dir) if not test_results.get_aggregate_success(): sys.exit(1)