Skip to content

Commit 9fc5106

Browse files
committed
Avoid using a new temp directory for each parallel test. NFC
It should be fine for all parallel tests to using the same TEMP_DIR. The only limitation is on tests that use the canonical test directory (e.g. EMCC_DEBUG). It looks like we used to use a unique temp directory per process (See #6150). However that we changes to one-directory-per-test in #18214, although I don't remember why. With this change we don't create a new temp directory except for tests that are marked as `uses_canonical_tmp`
1 parent b5bf368 commit 9fc5106

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

test/common.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,13 @@ def set_temp_dir(self, temp_dir):
699699
# Explicitly set dedicated temporary directory for parallel tests
700700
os.environ['EMCC_TEMP_DIR'] = self.temp_dir
701701

702+
def reset_temp_dir(self):
703+
# Deleting these instance fields will mean that the class field is used
704+
# instead.
705+
del self.temp_dir
706+
del self.canonical_temp_dir
707+
del os.environ['EMCC_TEMP_DIR']
708+
702709
def parse_wasm(self, filename):
703710
wat = self.get_wasm_text(filename)
704711
imports = []
@@ -797,7 +804,8 @@ def setUp(self):
797804
self.temp_files_before_run.append(os.path.normpath(os.path.join(root, filename)))
798805

799806
if self.runningInParallel():
800-
self.working_dir = tempfile.mkdtemp(prefix='emscripten_test_' + self.__class__.__name__ + '_', dir=self.temp_dir)
807+
# When running tests in parallel each test runs it its own new temp directory
808+
self.working_dir = tempfile.mkdtemp(prefix='emtest_' + self.__class__.__name__ + '_', dir=self.temp_dir)
801809
else:
802810
self.working_dir = path_from_root('out/test')
803811
if os.path.exists(self.working_dir):

test/parallel_testsuite.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,7 @@ def test_failed():
5353
with lock:
5454
allowed_failures_counter.value -= 1
5555

56-
olddir = os.getcwd()
5756
result = BufferedParallelTestResult(lock, progress_counter, num_tests)
58-
temp_dir = tempfile.mkdtemp(prefix='emtest_')
59-
test.set_temp_dir(temp_dir)
6057
try:
6158
if test.__class__ not in seen_class:
6259
seen_class.add(test.__class__)
@@ -71,10 +68,6 @@ def test_failed():
7168
except Exception as e:
7269
result.addError(test, e)
7370
test_failed()
74-
# Before attempting to delete the tmp dir make sure the current
75-
# working directory is not within it.
76-
os.chdir(olddir)
77-
common.force_delete_dir(temp_dir)
7871
return result
7972

8073

test/test_other.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import subprocess
2020
import sys
2121
import tarfile
22+
import tempfile
2223
import time
2324
from datetime import datetime
2425
from functools import wraps
@@ -142,6 +143,13 @@ def uses_canonical_tmp(func):
142143
"""
143144
@wraps(func)
144145
def decorated(self, *args, **kwargs):
146+
if self.runningInParallel():
147+
# Becuase the canical temp directory is global/central location when
148+
# tests use it in parallel they need to temporarily override the
149+
# temp directory to ovoid clobbering each each.
150+
new_temp = tempfile.mkdtemp(prefix='emtest_' + self.__class__.__name__ + '_', dir=self.temp_dir)
151+
self.set_temp_dir(new_temp)
152+
145153
# Before running the test completely remove the canonical_tmp
146154
if os.path.exists(self.canonical_temp_dir):
147155
shutil.rmtree(self.canonical_temp_dir)
@@ -155,6 +163,8 @@ def decorated(self, *args, **kwargs):
155163
# test fails we would not clean it up, and if leak detection
156164
# is set we will show that error instead of the actual one.
157165
shutil.rmtree(self.canonical_temp_dir)
166+
if self.runningInParallel():
167+
self.reset_temp_dir()
158168

159169
return decorated
160170

0 commit comments

Comments
 (0)