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.
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user