def _run_list(self, stats, result_set, test_inputs, jobs): h = self.host running_jobs = set() jobs = min(len(test_inputs), jobs) if not jobs: return child = _Child(self) pool = make_pool(h, jobs, _run_one_test, child, _setup_process, _teardown_process) try: while test_inputs or running_jobs: while test_inputs and (len(running_jobs) < self.args.jobs): test_input = test_inputs.pop(0) stats.started += 1 pool.send(test_input) running_jobs.add(test_input.name) self._print_test_started(stats, test_input) result = pool.get() running_jobs.remove(result.name) result_set.add(result) stats.finished += 1 self._print_test_finished(stats, result) pool.close() finally: pool.join()
def _run_list(self, stats, result_set, test_inputs, jobs): h = self.host running_jobs = set() jobs = min(len(test_inputs), jobs) if not jobs: return child = _Child(self) pool = make_pool(h, jobs, _run_one_test, child, _setup_process, _teardown_process) try: while test_inputs or running_jobs: while test_inputs and (len(running_jobs) < jobs): test_input = test_inputs.pop(0) stats.started += 1 pool.send(test_input) running_jobs.add(test_input.name) self._print_test_started(stats, test_input) result, should_retry_on_failure = pool.get() if (self.args.retry_only_retry_on_failure_tests and result.actual == ResultType.Failure and should_retry_on_failure): self.last_runs_retry_on_failure_tests.add(result.name) running_jobs.remove(result.name) result_set.add(result) stats.finished += 1 self._print_test_finished(stats, result) pool.close() finally: self.final_responses.extend(pool.join())
def test_join_discards_messages(self): host = Host() context = {'pre': False, 'post': False} pool = make_pool(host, 2, _echo, context, _pre, _post) pool.send('hello') pool.close() pool.join() self.assertEqual(len(pool.discarded_responses), 1)
def test_join_gets_an_error(self): host = Host() pool = make_pool(host, 2, _error, None, _stub, _stub) pool.send('hello') pool.close() try: pool.join() except Exception as e: self.assertIn('_error() raised Exception', str(e))
def run_basic_test(self, jobs): host = Host() context = {"pre": False, "post": False} pool = make_pool(host, jobs, _echo, context, _pre, _post) pool.send("hello") pool.send("world") msg1 = pool.get() msg2 = pool.get() pool.close() final_contexts = pool.join() self.assertEqual(set([msg1, msg2]), set(["True/False/hello", "True/False/world"])) expected_context = {"pre": True, "post": True} expected_final_contexts = [expected_context for _ in range(jobs)] self.assertEqual(final_contexts, expected_final_contexts)
def run_basic_test(self, jobs): host = Host() context = {'pre': False, 'post': False} pool = make_pool(host, jobs, _echo, context, _pre, _post) pool.send('hello') pool.send('world') msg1 = pool.get() msg2 = pool.get() pool.close() final_contexts = pool.join() self.assertEqual(set([msg1, msg2]), set(['True/False/hello', 'True/False/world'])) expected_context = {'pre': True, 'post': True} expected_final_contexts = [expected_context for _ in range(jobs)] self.assertEqual(final_contexts, expected_final_contexts)
def test_join_gets_an_interrupt(self): host = Host() pool = make_pool(host, 2, _interrupt, None, _stub, _stub) pool.send('hello') pool.close() self.assertRaises(KeyboardInterrupt, pool.join)
def _run_tests(self, result_set, test_set, all_tests): h = self.host self.last_runs_retry_on_failure_tests = set() def get_tests_to_retry(results): # If the --retry-only-retry-on-failure-tests command line argument # is passed , then a set of test failures with the RetryOnFailure # expectation from the last run of tests will be returned. The # self.last_runs_retry_on_failure_tests will be set to an empty set # for the next run of tests. Otherwise all regressions from the # last run will be returned. if self.args.retry_only_retry_on_failure_tests: ret = self.last_runs_retry_on_failure_tests.copy() self.last_runs_retry_on_failure_tests = set() return ret else: return json_results.regressions(results) if len(test_set.parallel_tests): jobs = min( len(test_set.parallel_tests), self.args.jobs) else: jobs = 1 child = _Child(self) pool = make_pool(h, jobs, _run_one_test, child, _setup_process, _teardown_process) self._run_one_set(self.stats, result_set, test_set, jobs, pool) tests_to_retry = sorted(get_tests_to_retry(result_set)) retry_limit = self.args.retry_limit try: # Start at 1 since we already did iteration 0 above. for iteration in range(1, self.args.retry_limit + 1): if not tests_to_retry: break if retry_limit == self.args.retry_limit: self.flush() self.args.overwrite = False self.printer.should_overwrite = False self.args.verbose = min(self.args.verbose, 1) self.print_('') self.print_('Retrying failed tests (attempt #%d of %d)...' % (iteration, self.args.retry_limit)) self.print_('') stats = Stats(self.args.status_format, h.time, 1) stats.total = len(tests_to_retry) test_set = TestSet(self.args.test_name_prefix) test_set.isolated_tests = [ TestInput(name, iteration=iteration) for name in tests_to_retry] tests_to_retry = test_set retry_set = ResultSet() self._run_one_set(stats, retry_set, tests_to_retry, 1, pool) result_set.results.extend(retry_set.results) tests_to_retry = get_tests_to_retry(retry_set) retry_limit -= 1 pool.close() finally: self.final_responses.extend(pool.join()) if retry_limit != self.args.retry_limit: self.print_('') full_results = json_results.make_full_results(self.metadata, int(h.time()), all_tests, result_set, self.path_delimiter) retcode = (json_results.exit_code_from_full_results(full_results) | result_sink.result_sink_retcode_from_result_set(result_set)) return (retcode, full_results)
def test_no_close(self): host = Host() context = {'pre': False, 'post': False} pool = make_pool(host, 2, _echo, context, _pre, _post) final_contexts = pool.join() self.assertEqual(final_contexts, [])
def test_async_close(self): host = Host() pool = make_pool(host, 1, _echo, None, _stub, _stub) pool.join()