Skip to content

Commit

Permalink
[SPARK-39621][PYTHON][TESTS] Make run-tests.py robust by avoiding `…
Browse files Browse the repository at this point in the history
…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 apache#37010 from dongjoon-hyun/SPARK-39621.

Authored-by: Dongjoon Hyun <dongjoon@apache.org>
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
  • Loading branch information
dongjoon-hyun committed Jun 27, 2022
1 parent e7fd1a6 commit 432945d
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion python/run-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import logging
from argparse import ArgumentParser
import os
import platform
import re
import shutil
import subprocess
Expand Down Expand Up @@ -113,7 +114,12 @@ def run_individual_python_test(target_dir, test_name, pyspark_python):
retcode = subprocess.Popen(
[os.path.join(SPARK_HOME, "bin/pyspark")] + test_name.split(),
stderr=per_test_output, stdout=per_test_output, env=env).wait()
shutil.rmtree(tmp_dir, ignore_errors=True)
# There exists a race condition in Python and it causes flakiness in MacOS
# https://github.com/python/cpython/issues/73885
if platform.system() == "Darwin":
os.system("rm -rf " + tmp_dir)
else:
shutil.rmtree(tmp_dir, ignore_errors=True)
except BaseException:
LOGGER.exception("Got exception while running %s with %s", test_name, pyspark_python)
# Here, we use os._exit() instead of sys.exit() in order to force Python to exit even if
Expand Down

0 comments on commit 432945d

Please sign in to comment.