Skip to content

Commit 02ff1cc

Browse files
gh-84461: Fix parallel testing on WebAssembly (GH-93768)
(cherry picked from commit c200757) Co-authored-by: Christian Heimes <christian@python.org>
1 parent dc6dd8e commit 02ff1cc

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

Lib/test/libregrtest/main.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -628,11 +628,16 @@ def create_temp_dir(self):
628628
# Define a writable temp dir that will be used as cwd while running
629629
# the tests. The name of the dir includes the pid to allow parallel
630630
# testing (see the -j option).
631-
pid = os.getpid()
631+
# Emscripten and WASI have stubbed getpid(), Emscripten has only
632+
# milisecond clock resolution. Use randint() instead.
633+
if sys.platform in {"emscripten", "wasi"}:
634+
nounce = random.randint(0, 1_000_000)
635+
else:
636+
nounce = os.getpid()
632637
if self.worker_test_name is not None:
633-
test_cwd = 'test_python_worker_{}'.format(pid)
638+
test_cwd = 'test_python_worker_{}'.format(nounce)
634639
else:
635-
test_cwd = 'test_python_{}'.format(pid)
640+
test_cwd = 'test_python_{}'.format(nounce)
636641
test_cwd += os_helper.FS_NONASCII
637642
test_cwd = os.path.join(self.tmp_dir, test_cwd)
638643
return test_cwd

Tools/scripts/run_tests.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ def main(regrtest_args):
6363
args.append('-n') # Silence alerts under Windows
6464
if not any(is_multiprocess_flag(arg) for arg in regrtest_args):
6565
if cross_compile and hostrunner:
66-
# For now use only one core for cross-compiled builds;
66+
# For now use only two cores for cross-compiled builds;
6767
# hostrunner can be expensive.
68-
args.extend(['-j', '1'])
68+
args.extend(['-j', '2'])
6969
else:
7070
args.extend(['-j', '0']) # Use all CPU cores
7171
if not any(is_resource_use_flag(arg) for arg in regrtest_args):

0 commit comments

Comments
 (0)