aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Schneider <nioncode+git@gmail.com>2016-04-06 12:38:39 +0200
committerNicolas Schneider <nioncode+git@gmail.com>2016-04-06 12:38:39 +0200
commit32e0973ef1e502e22e3c848dad5279b4d58e044b (patch)
treec538ac306eac66654a09065bf32afc93e255420c
parent42e6b78351a05eeb284bb287aa2b5e4e84e1d94d (diff)
downloadmeson-32e0973ef1e502e22e3c848dad5279b4d58e044b.zip
meson-32e0973ef1e502e22e3c848dad5279b4d58e044b.tar.gz
meson-32e0973ef1e502e22e3c848dad5279b4d58e044b.tar.bz2
fix randomly failing test execution on Windows
shutil.rmtree, which is used by tempfile.TemporaryDirectory, randomly fails on Windows, because the directory is not empty although it should be, because all files were deleted by shutil.rmtree internals before trying to remove the directory. A simple retry approach fixes the issue.
-rwxr-xr-xrun_tests.py23
1 files changed, 21 insertions, 2 deletions
diff --git a/run_tests.py b/run_tests.py
index 3a5ccbd..f8d6aa2 100755
--- a/run_tests.py
+++ b/run_tests.py
@@ -42,6 +42,25 @@ class TestResult:
self.buildtime = buildtime
self.testtime = testtime
+class AutoDeletedDir():
+ def __init__(self, dir):
+ self.dir = dir
+ def __enter__(self):
+ os.makedirs(self.dir, exist_ok=True)
+ return self.dir
+ def __exit__(self, type, value, traceback):
+ # On Windows, shutil.rmtree fails sometimes, because 'the directory is not empty'.
+ # Retrying fixes this.
+ # That's why we don't use tempfile.TemporaryDirectory, but wrap the deletion in the AutoDeletedDir class.
+ retries = 5
+ for i in range(0, retries):
+ try:
+ shutil.rmtree(self.dir)
+ return
+ except OSError:
+ if i == retries:
+ raise
+
passing_tests = 0
failing_tests = 0
skipped_tests = 0
@@ -200,8 +219,8 @@ def parse_test_args(testdir):
def run_test(skipped, testdir, extra_args, flags, compile_commands, install_commands, should_succeed):
if skipped:
return None
- with tempfile.TemporaryDirectory(prefix='b ', dir='.') as build_dir:
- with tempfile.TemporaryDirectory(prefix='i ', dir=os.getcwd()) as install_dir:
+ with AutoDeletedDir(tempfile.mkdtemp(prefix='b ', dir='.')) as build_dir:
+ with AutoDeletedDir(tempfile.mkdtemp(prefix='i ', dir=os.getcwd())) as install_dir:
try:
return _run_test(testdir, build_dir, install_dir, extra_args, flags, compile_commands, install_commands, should_succeed)
finally: