From c76797f1d781814691023bae84332ede6254a3a9 Mon Sep 17 00:00:00 2001 From: Masen Furer Date: Thu, 12 Dec 2024 03:52:28 -0800 Subject: [PATCH] Improve assertions in test_cancel_upload --- tests/integration/test_upload.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/tests/integration/test_upload.py b/tests/integration/test_upload.py index b7f14b03d..156cf0e45 100644 --- a/tests/integration/test_upload.py +++ b/tests/integration/test_upload.py @@ -381,9 +381,22 @@ async def test_cancel_upload(tmp_path, upload_file: AppHarness, driver: WebDrive await asyncio.sleep(0.3) cancel_button.click() - # look up the backend state and assert on progress + # Wait a bit for the upload to get cancelled. + await asyncio.sleep(0.5) + + # Get interim progress dicts saved in the on_upload_progress handler. + async def _progress_dicts(): + state = await upload_file.get_state(substate_token) + return state.substates[state_name].progress_dicts + + # We should have _some_ progress + assert await AppHarness._poll_for_async(_progress_dicts) + + # But there should never be a final progress record for a cancelled upload. + for p in await _progress_dicts(): + assert p["progress"] != 1 + state = await upload_file.get_state(substate_token) - assert state.substates[state_name].progress_dicts file_data = state.substates[state_name]._file_data assert isinstance(file_data, dict) normalized_file_data = {Path(k).name: v for k, v in file_data.items()}