From d8eaff4fa4bcbd1d0840f757d29a65e5bf26458c Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Mon, 13 Jun 2022 14:25:40 +0200 Subject: [PATCH 1/2] gh-84461: Fix parallel testing on WebAssembly Emscripten and WASI have stubbed getpid() syscall that always returns the same value. Use time and random value instead of pid to create a unique working directory. --- Lib/test/libregrtest/main.py | 7 ++++++- Tools/scripts/run_tests.py | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Lib/test/libregrtest/main.py b/Lib/test/libregrtest/main.py index 0cacccfc0b5e39..23fdd3bf7a3d69 100644 --- a/Lib/test/libregrtest/main.py +++ b/Lib/test/libregrtest/main.py @@ -628,7 +628,12 @@ def create_temp_dir(self): # Define a writable temp dir that will be used as cwd while running # the tests. The name of the dir includes the pid to allow parallel # testing (see the -j option). - pid = os.getpid() + # Emscripten and WASI have stubbed getpid(), Emscripten has only + # milisecond clock resolution. Use time_ns() + randint() instead. + if sys.platform in {"emscripten", "wasi"}: + pid = time.time_ns() + random.randint(0, 1000000) + else: + pid = os.getpid() if self.worker_test_name is not None: test_cwd = 'test_python_worker_{}'.format(pid) else: diff --git a/Tools/scripts/run_tests.py b/Tools/scripts/run_tests.py index 8dbcade9238551..445a34ae3e8eee 100644 --- a/Tools/scripts/run_tests.py +++ b/Tools/scripts/run_tests.py @@ -63,9 +63,9 @@ def main(regrtest_args): args.append('-n') # Silence alerts under Windows if not any(is_multiprocess_flag(arg) for arg in regrtest_args): if cross_compile and hostrunner: - # For now use only one core for cross-compiled builds; + # For now use only two cores for cross-compiled builds; # hostrunner can be expensive. - args.extend(['-j', '1']) + args.extend(['-j', '2']) else: args.extend(['-j', '0']) # Use all CPU cores if not any(is_resource_use_flag(arg) for arg in regrtest_args): From e0142c6870b9a1d62aa01f07c676fbb9e1832b49 Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Mon, 13 Jun 2022 19:25:00 +0200 Subject: [PATCH 2/2] Rename var, use randint() only --- Lib/test/libregrtest/main.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Lib/test/libregrtest/main.py b/Lib/test/libregrtest/main.py index 23fdd3bf7a3d69..85bf6e1d48e3a7 100644 --- a/Lib/test/libregrtest/main.py +++ b/Lib/test/libregrtest/main.py @@ -629,15 +629,15 @@ def create_temp_dir(self): # the tests. The name of the dir includes the pid to allow parallel # testing (see the -j option). # Emscripten and WASI have stubbed getpid(), Emscripten has only - # milisecond clock resolution. Use time_ns() + randint() instead. + # milisecond clock resolution. Use randint() instead. if sys.platform in {"emscripten", "wasi"}: - pid = time.time_ns() + random.randint(0, 1000000) + nounce = random.randint(0, 1_000_000) else: - pid = os.getpid() + nounce = os.getpid() if self.worker_test_name is not None: - test_cwd = 'test_python_worker_{}'.format(pid) + test_cwd = 'test_python_worker_{}'.format(nounce) else: - test_cwd = 'test_python_{}'.format(pid) + test_cwd = 'test_python_{}'.format(nounce) test_cwd += os_helper.FS_NONASCII test_cwd = os.path.join(self.tmp_dir, test_cwd) return test_cwd