From 996bcd3372751d725a4f68e5d6666a28cb4ef0c0 Mon Sep 17 00:00:00 2001 From: Vito Sansevero Date: Mon, 26 Oct 2026 07:12:16 -0700 Subject: [PATCH] test(restore): wait for the cancelled preview's worker before teardown (#350) py3.13 on ubuntu-latest failed on PR #351 (run 40334794505) with 'Files still open at teardown: prompts.db, prompts.db-shm' in test_cancel_while_reading_the_live_library. Cancelling the preview cannot stop its executor thread, which goes on to open the live library; the test returned without waiting, so that open could land between teardown's close_all_instances() and assert_closed(). The test now waits for the worker, as test_cancel_while_staging already does. --- tests/test_restore_review_fixes.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/test_restore_review_fixes.py b/tests/test_restore_review_fixes.py index 4f2f16e9..62def53b 100644 --- a/tests/test_restore_review_fixes.py +++ b/tests/test_restore_review_fixes.py @@ -291,11 +291,15 @@ class TestCancelledPreview(RestoreTestCase): self.upload(["restored"], "up.db") entered, release = threading.Event(), threading.Event() real = self.api._live_fingerprint + done = threading.Event() def slow(db): entered.set() release.wait(WAIT) - return real(db) + try: + return real(db) + finally: + done.set() with patch.object(self.api, "_live_fingerprint", side_effect=slow): task = asyncio.ensure_future( @@ -310,6 +314,9 @@ class TestCancelledPreview(RestoreTestCase): release.set() with self.assertRaises(asyncio.CancelledError): await task + # The cancel cannot stop the worker thread: it still opens the live + # library. Let it finish, or teardown can find the file open. + self.assertTrue(await loop.run_in_executor(None, done.wait, WAIT)) self.assertEqual(self.stages(), []) self.assertEqual(len(self.api._restore_plans), 0)