From 098f04d8c8cf902f7dd51efdea194e6d52f4e2ec Mon Sep 17 00:00:00 2001 From: Adam Dangoor Date: Sun, 14 Jul 2024 09:52:51 +0100 Subject: [PATCH] Simplify test_database_summary test for future debugging --- tests/mock_vws/test_database_summary.py | 64 +++++++++++++------------ 1 file changed, 33 insertions(+), 31 deletions(-) diff --git a/tests/mock_vws/test_database_summary.py b/tests/mock_vws/test_database_summary.py index 8512037fd..8ee7d0871 100644 --- a/tests/mock_vws/test_database_summary.py +++ b/tests/mock_vws/test_database_summary.py @@ -53,7 +53,7 @@ def _wait_for_image_numbers( ValueError: The numbers of images in various categories do not match within the time limit. """ - requirements = { + expected = { "active_images": active_images, "inactive_images": inactive_images, "failed_images": failed_images, @@ -72,36 +72,38 @@ def _wait_for_image_numbers( # request quota. sleep_seconds = 0.2 - for key, value in requirements.items(): - while True: - seconds_waited = time.monotonic() - start_time - if seconds_waited > maximum_wait_seconds: # pragma: no cover - timeout_message = "Timed out waiting" - raise ValueError(timeout_message) - - report = vws_client.get_database_summary_report() - key_to_relevant_images_in_summary = { - "active_images": report.active_images, - "inactive_images": report.inactive_images, - "failed_images": report.failed_images, - "processing_images": report.processing_images, - } - relevant_images_in_summary = key_to_relevant_images_in_summary[key] - if value != relevant_images_in_summary: # pragma: no cover - message = ( - f"Expected {value} `{key}`s. " - f"Found {relevant_images_in_summary} `{key}`s. " - f"We have waited {int(seconds_waited)} second(s)." - ) - LOGGER.debug(msg=message) - - time.sleep(sleep_seconds) - - # This makes the entire test invalid. - # However, we have found that without this Vuforia is flaky. - # We have waited over 10 minutes for the summary to change and - # that is not sustainable in a test suite. - break + while True: + seconds_waited = time.monotonic() - start_time + if seconds_waited > maximum_wait_seconds: # pragma: no cover + timeout_message = "Timed out waiting" + raise ValueError(timeout_message) + + database_summary_report = vws_client.get_database_summary_report() + actual = { + "active_images": database_summary_report.active_images, + "inactive_images": database_summary_report.inactive_images, + "failed_images": database_summary_report.failed_images, + "processing_images": database_summary_report.processing_images, + } + if actual == expected: + return + + message = ( + f"Expected {expected}. " + f"Found {actual}. " + f"We have waited {int(seconds_waited)} second(s)." + ) + LOGGER.debug(msg=message) + + time.sleep(sleep_seconds) + + # This break makes the entire test invalid. + # However, we have found that without this Vuforia is flaky. + # We have waited over 10 minutes for the summary to change and + # that is not sustainable in a test suite. + # That might be because we think some images will go into a particular + # state but they don't. + break @pytest.mark.usefixtures("verify_mock_vuforia")