From 8f14d988a1ec969eaa456c8c87683a073e0646b0 Mon Sep 17 00:00:00 2001 From: Vlada Dusek Date: Wed, 29 Apr 2026 16:40:51 +0200 Subject: [PATCH] test: replace fixed sleep with poll_until_condition in test_cache_initialization The fixed `asyncio.sleep(10)` waits weren't always enough for Apify platform stats to propagate, causing intermittent CI failures. Switch to the existing `poll_until_condition` helper used elsewhere in the file. --- tests/integration/test_request_queue.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/tests/integration/test_request_queue.py b/tests/integration/test_request_queue.py index 2d8d3250..ab8967d2 100644 --- a/tests/integration/test_request_queue.py +++ b/tests/integration/test_request_queue.py @@ -986,9 +986,13 @@ async def test_cache_initialization(apify_token: str, monkeypatch: pytest.Monkey try: await rq.add_requests(requests) - # Check that it is correctly in the API - await asyncio.sleep(10) # Wait to be sure that metadata are updated - metadata = cast('ApifyRequestQueueMetadata', await rq.get_metadata()) + async def _get_rq_metadata() -> ApifyRequestQueueMetadata: + return cast('ApifyRequestQueueMetadata', await rq.get_metadata()) + + metadata = await poll_until_condition( + _get_rq_metadata, + lambda m: m.stats.write_count >= len(requests), + ) stats_before = metadata.stats Actor.log.info(stats_before) @@ -999,8 +1003,10 @@ async def test_cache_initialization(apify_token: str, monkeypatch: pytest.Monkey rq = await Actor.open_request_queue(name=request_queue_name, force_cloud=True) await rq.add_requests(requests) - await asyncio.sleep(10) # Wait to be sure that metadata are updated - metadata = cast('ApifyRequestQueueMetadata', await rq.get_metadata()) + metadata = await poll_until_condition( + _get_rq_metadata, + lambda m: m.stats.read_count - stats_before.read_count >= len(requests), + ) stats_after = metadata.stats Actor.log.info(stats_after)