From 8cb4a8aebab96ed0bdf7f9997e7a5b99c8cbed51 Mon Sep 17 00:00:00 2001 From: Vlada Dusek Date: Wed, 11 Feb 2026 12:57:07 +0100 Subject: [PATCH] test: fix flaky test_large_batch_operations by adding retry on empty fetches The test was flaky because fetch_next_request() can temporarily return None due to eventual consistency in the Apify API, even when is_empty() reports requests still exist. Replace the while-not-is_empty loop with a retry pattern that tolerates up to 10 consecutive empty fetches before concluding the queue is drained. Co-Authored-By: Claude Opus 4.6 --- .../integration/apify_api/test_request_queue.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tests/integration/apify_api/test_request_queue.py b/tests/integration/apify_api/test_request_queue.py index e90c1600..effaf7b2 100644 --- a/tests/integration/apify_api/test_request_queue.py +++ b/tests/integration/apify_api/test_request_queue.py @@ -548,15 +548,19 @@ async def test_large_batch_operations(request_queue_apify: RequestQueue) -> None total_count = await rq.get_total_count() assert total_count == 500, f'total_count={total_count}' - # Process all in chunks to test performance + # Process all requests using a retry loop to handle eventual consistency — + # fetch_next_request() can temporarily return None even when requests exist. processed_count = 0 + max_consecutive_empty_fetches = 10 + consecutive_empty_fetches = 0 - while not await rq.is_empty(): + while consecutive_empty_fetches < max_consecutive_empty_fetches: request = await rq.fetch_next_request() - - # The RQ is_empty should ensure we don't get None - assert request is not None, f'request={request}' - + if request is None: + consecutive_empty_fetches += 1 + await asyncio.sleep(0.5) + continue + consecutive_empty_fetches = 0 await rq.mark_request_as_handled(request) processed_count += 1