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)