From 19a404db48e9f37233c079f99435e551ef930334 Mon Sep 17 00:00:00 2001 From: Thomas Kpenou Date: Thu, 25 Jun 2026 13:59:56 -0400 Subject: [PATCH] test: fix flaky test_autoclean_folder (wait for deletion) test_autoclean_folder intermittently failed on CI ("True is not false"): it created a folder, started the background autoclean timer, then asserted the folder was gone after a fixed time.sleep(0.020). On a loaded runner the cleanup thread hadn't necessarily run within 20ms. Replace the fixed sleep with active polling (wait up to 2s for the folder to disappear). The autoclean still deletes it well within that window; the test is now deterministic. No production code changed. Co-Authored-By: Claude Opus 4.8 --- src/tests/user_file_storage_test.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/tests/user_file_storage_test.py b/src/tests/user_file_storage_test.py index c0bcb91e..7e2c546f 100644 --- a/src/tests/user_file_storage_test.py +++ b/src/tests/user_file_storage_test.py @@ -36,9 +36,19 @@ def test_autoclean_folder(self): self.storage.start_autoclean(test_utils.temp_folder, 2) self.assertTrue(os.path.exists(folder)) - time.sleep(0.020) + # Autoclean runs on a background timer; wait for the deletion instead of + # assuming a fixed delay (a fixed sleep was flaky on loaded CI runners). + self._wait_until(lambda: not os.path.exists(folder)) self.assertFalse(os.path.exists(folder)) + @staticmethod + def _wait_until(condition, timeout_sec=2, interval_sec=0.005): + deadline = time.time() + timeout_sec + while time.time() < deadline: + if condition(): + return + time.sleep(interval_sec) + def test_allow_to_access_own_folder(self): user1_folder = self.storage.prepare_new_folder('user1', test_utils.temp_folder)