def main(args=None): """Run tests, rerunning at most MAX_RETRY_COUNT times if they flake.""" parsed_args = _PARSER.parse_args(args=args) policy = RERUN_POLICIES[parsed_args.suite.lower()] with servers.managed_portserver(): for attempt_num in python_utils.RANGE(1, MAX_RETRY_COUNT + 1): python_utils.PRINT('***Attempt %d.***' % attempt_num) output, return_code = run_tests(parsed_args) if not flake_checker.check_if_on_ci(): # Don't rerun off of CI. python_utils.PRINT('No reruns because not running on CI.') break if return_code == 0: # Don't rerun passing tests. flake_checker.report_pass(parsed_args.suite) break # Check whether we should rerun based on this suite's policy. test_is_flaky = flake_checker.is_test_output_flaky( output, parsed_args.suite) if policy == RERUN_POLICY_NEVER: break if policy == RERUN_POLICY_KNOWN_FLAKES and not test_is_flaky: break sys.exit(return_code)
def test_managed_portserver_removes_existing_socket(self): original_os_remove = os.remove original_os_path_exists = os.path.exists @test_utils.CallCounter def mock_os_remove(path): if path == common.PORTSERVER_SOCKET_FILEPATH: return original_os_remove(path) def mock_os_path_exists(path): if path == common.PORTSERVER_SOCKET_FILEPATH: return True original_os_path_exists(path) popen_calls = self.exit_stack.enter_context(self.swap_popen()) self.exit_stack.enter_context( self.swap_with_checks(os.path, 'exists', mock_os_path_exists)) self.exit_stack.enter_context( self.swap_with_checks(os, 'remove', mock_os_remove)) proc = self.exit_stack.enter_context(servers.managed_portserver()) self.exit_stack.close() self.assertEqual(len(popen_calls), 1) self.assertEqual( popen_calls[0].program_args, 'python -m scripts.run_portserver ' '--portserver_unix_socket_address %s' % (common.PORTSERVER_SOCKET_FILEPATH), ) self.assertEqual(proc.signals_received, [signal.SIGINT]) self.assertEqual(mock_os_remove.times_called, 1)
def main(args=None): """Run tests, rerunning at most MAX_RETRY_COUNT times if they flake.""" parsed_args = _PARSER.parse_args(args=args) with servers.managed_portserver(): for attempt_num in python_utils.RANGE(1, MAX_RETRY_COUNT + 1): python_utils.PRINT('***Attempt %d.***' % attempt_num) output, return_code = run_tests(parsed_args) if not flake_checker.check_if_on_ci(): # Don't rerun off of CI. python_utils.PRINT('No reruns because not running on CI.') break if return_code == 0: # Don't rerun passing tests. flake_checker.report_pass(parsed_args.suite) break test_is_flaky = flake_checker.is_test_output_flaky( output, parsed_args.suite) if not test_is_flaky and not RERUN_NON_FLAKY: # Don't rerun if the test was non-flaky and we are not rerunning # non-flaky tests. break sys.exit(return_code)
def test_managed_portserver(self): popen_calls = self.exit_stack.enter_context(self.swap_popen()) proc = self.exit_stack.enter_context(servers.managed_portserver()) self.exit_stack.close() self.assertEqual(len(popen_calls), 1) self.assertEqual( popen_calls[0].program_args, 'python -m scripts.run_portserver ' '--portserver_unix_socket_address %s' % (common.PORTSERVER_SOCKET_FILEPATH), ) self.assertEqual(proc.signals_received, [signal.SIGINT]) self.assertEqual(proc.terminate_count, 0) self.assertEqual(proc.kill_count, 0)
def main(args=None): """Run tests, rerunning at most MAX_RETRY_COUNT times if they flake.""" parsed_args = _PARSER.parse_args(args=args) policy = RERUN_POLICIES[parsed_args.suite.lower()] with servers.managed_portserver(): for attempt_num in range(1, MAX_RETRY_COUNT + 1): print('***Attempt %d.***' % attempt_num) output, return_code = run_tests(parsed_args) if not flake_checker.check_if_on_ci(): # Don't rerun off of CI. print('No reruns because not running on CI.') break if return_code == 0: # Don't rerun passing tests. flake_checker.report_pass(parsed_args.suite) break # Check whether we should rerun based on this suite's policy # and override instructions from the flake checker server. test_is_flaky, rerun_override = flake_checker.is_test_output_flaky( output, parsed_args.suite) if rerun_override == flake_checker.RERUN_YES: print('Rerunning as per instructions from logging ' 'server.') elif rerun_override == flake_checker.RERUN_NO: print('Not rerunning as per instructions from ' 'logging server.') break # No rerun override, so follow rerun policies. elif policy == RERUN_POLICY_NEVER: print('Not rerunning because the policy is to never ' 'rerun the {} suite'.format(parsed_args.suite)) break elif policy == RERUN_POLICY_KNOWN_FLAKES and not test_is_flaky: print(('Not rerunning because the policy is to only ' 'rerun the %s suite on known flakes, and this ' 'failure did not match any known flakes') % parsed_args.suite) break # Else rerun policy is either always or we had a known flake # with a known flakes rerun policy, so rerun. sys.exit(return_code)
def test_managed_portserver_when_unresponsive(self): popen_calls = self.exit_stack.enter_context(self.swap_popen()) proc = self.exit_stack.enter_context(servers.managed_portserver()) proc.unresponsive = True self.exit_stack.close() self.assertEqual(len(popen_calls), 1) self.assertEqual(popen_calls[0].program_args, [ 'python', '-m', 'scripts.run_portserver', '--portserver_unix_socket_address', common.PORTSERVER_SOCKET_FILEPATH, ]) self.assertEqual(proc.signals_received, [signal.SIGINT]) self.assertEqual(proc.terminate_count, 1) self.assertEqual(proc.kill_count, 1)
def test_managed_portserver_when_unresponsive(self): popen_calls = self.exit_stack.enter_context(self.swap_popen()) proc = self.exit_stack.enter_context(servers.managed_portserver()) proc.unresponsive = True with self.assertRaisesRegex( Exception, 'Process Portserver.* exited unexpectedly with exit code 1'): self.exit_stack.close() self.assertEqual(len(popen_calls), 1) self.assertEqual( popen_calls[0].program_args, 'python -m scripts.run_portserver ' '--portserver_unix_socket_address %s' % (common.PORTSERVER_SOCKET_FILEPATH), ) self.assertEqual(proc.signals_received, [signal.SIGINT]) self.assertEqual(proc.terminate_count, 1) self.assertEqual(proc.kill_count, 1)