From 8bb1c12040dbddef646a439c9486c74e80470162 Mon Sep 17 00:00:00 2001 From: Alex Hoppen Date: Wed, 6 Nov 2024 11:03:35 -0800 Subject: [PATCH] Re-run tests serially if parallel testing failed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use the same approach that we’ve taken in SourceKit-LSP to capture more actionable output. --- Utilities/build-script-helper.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Utilities/build-script-helper.py b/Utilities/build-script-helper.py index 215905f5..ce7aed27 100755 --- a/Utilities/build-script-helper.py +++ b/Utilities/build-script-helper.py @@ -41,6 +41,8 @@ def check_call(cmd: List[str], additional_env: Dict[str, str] = {}, verbose: boo if verbose: print_cmd(cmd=cmd, additional_env=additional_env) + sys.stdout.flush() + sys.stderr.flush() subprocess.check_call(cmd, env=env_with_additional_env(additional_env), stderr=subprocess.STDOUT) @@ -51,6 +53,8 @@ def check_output(cmd: List[str], additional_env: Dict[str, str] = {}, capture_st stderr = subprocess.STDOUT else: stderr = subprocess.DEVNULL + sys.stdout.flush() + sys.stderr.flush() return subprocess.check_output(cmd, env=env_with_additional_env(additional_env), stderr=stderr, encoding='utf-8') # ----------------------------------------------------------------------------- @@ -150,8 +154,14 @@ def run_tests(swift_exec: str, args: argparse.Namespace) -> None: print('Cleaning ' + tests) shutil.rmtree(tests, ignore_errors=True) - cmd = [swift_exec, 'test', '--parallel', '--test-product', 'IndexStoreDBPackageTests'] + swiftpm_args - check_call(cmd, additional_env=additional_env, verbose=args.verbose) + cmd = [swift_exec, 'test', '--test-product', 'IndexStoreDBPackageTests'] + swiftpm_args + try: + check_call(cmd + ['--parallel'], additional_env=additional_env, verbose=args.verbose) + except: + print('--- Running tests in parallel failed. Re-running tests serially to capture more actionable output.') + check_call(cmd, additional_env=additional_env, verbose=args.verbose) + # Return with non-zero exit code even if serial test execution succeeds. + raise SystemExit(1) def handle_invocation(swift_exec: str, args: argparse.Namespace) -> None: