From 71b1eaf2fe7d741fe8a8c68f08e7c3b675369bad Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Sun, 26 Jun 2022 14:00:01 +0930 Subject: [PATCH] pyln-testing: try harder if cleaning directory fails. This happens under CI, but it's not informative. Sleep and retry. Also, "except (OSError, Exception)" does not seem to do what you'd think: this clause never gets run. Signed-off-by: Rusty Russell --- contrib/pyln-testing/pyln/testing/fixtures.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/contrib/pyln-testing/pyln/testing/fixtures.py b/contrib/pyln-testing/pyln/testing/fixtures.py index d576a3aba..e2c26de40 100644 --- a/contrib/pyln-testing/pyln/testing/fixtures.py +++ b/contrib/pyln-testing/pyln/testing/fixtures.py @@ -14,6 +14,7 @@ import shutil import string import sys import tempfile +import time # A dict in which we count how often a particular test has run so far. Used to @@ -94,10 +95,14 @@ def directory(request, test_base_dir, test_name): if not failed: try: shutil.rmtree(directory) - except (OSError, Exception): + except OSError: + # Usually, this means that e.g. valgrind is still running. Wait + # a little and retry. files = [os.path.join(dp, f) for dp, dn, fn in os.walk(directory) for f in fn] - print("Directory still contains files:", files) - raise + print("Directory still contains files: ", files) + print("... sleeping then retrying") + time.sleep(10) + shutil.rmtree(directory) else: logging.debug("Test execution failed, leaving the test directory {} intact.".format(directory))