Skip to content

Commit cf72e52

Browse files
committed
[SPARK-39621][PYTHON][TESTS] Make run-tests.py robust by avoiding rmtree on MacOS
### What changes were proposed in this pull request? This PR aims to make `run-tests.py` robust by avoiding `rmtree` on MacOS. ### Why are the changes needed? There exists a race condition in Python and it causes flakiness in MacOS - https://bugs.python.org/issue29699 - python/cpython#73885 ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? After passing CIs, this should be tested on MacOS. Closes #37010 from dongjoon-hyun/SPARK-39621. Authored-by: Dongjoon Hyun <[email protected]> Signed-off-by: Dongjoon Hyun <[email protected]> (cherry picked from commit 432945d) Signed-off-by: Dongjoon Hyun <[email protected]>
1 parent 7e1a329 commit cf72e52

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

python/run-tests.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import logging
2121
from argparse import ArgumentParser
2222
import os
23+
import platform
2324
import re
2425
import shutil
2526
import subprocess
@@ -113,7 +114,12 @@ def run_individual_python_test(target_dir, test_name, pyspark_python):
113114
retcode = subprocess.Popen(
114115
[os.path.join(SPARK_HOME, "bin/pyspark")] + test_name.split(),
115116
stderr=per_test_output, stdout=per_test_output, env=env).wait()
116-
shutil.rmtree(tmp_dir, ignore_errors=True)
117+
# There exists a race condition in Python and it causes flakiness in MacOS
118+
# https://github.com/python/cpython/issues/73885
119+
if platform.system() == "Darwin":
120+
os.system("rm -rf " + tmp_dir)
121+
else:
122+
shutil.rmtree(tmp_dir, ignore_errors=True)
117123
except BaseException:
118124
LOGGER.exception("Got exception while running %s with %s", test_name, pyspark_python)
119125
# Here, we use os._exit() instead of sys.exit() in order to force Python to exit even if

0 commit comments

Comments
 (0)