Skip to content

Commit 44e03e0

Browse files
committed
test: poll for lock propagation instead of fixed sleep
Use the poll_until_condition helper to wait until the locked requests drop out of the queue head, rather than a fixed eventual-consistency sleep before unlocking.
1 parent 45b7219 commit 44e03e0

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

‎tests/integration/test_request_queue.py‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
get_random_string,
1313
maybe_await,
1414
maybe_sleep,
15+
poll_until_condition,
1516
)
1617
from apify_client._models import (
1718
BatchAddResult,
@@ -560,11 +561,18 @@ async def test_request_queue_unlock_requests(client: ApifyClient | ApifyClientAs
560561
assert isinstance(result, LockedRequestQueueHead)
561562
lock_response = result
562563
assert len(lock_response.items) == 3
563-
564-
# Wait briefly for eventual consistency: the lock-head response is acknowledged before all
565-
# three lock writes have propagated to the replica that `unlock_requests` reads, so unlocking
566-
# immediately can see fewer locks than were just acquired.
567-
await maybe_sleep(3, is_async=is_async)
564+
locked_ids = {item.id for item in lock_response.items}
565+
566+
# Wait for the locks to propagate before unlocking (eventual consistency): the lock-head response
567+
# is acknowledged before all three lock writes are visible to subsequent reads, so unlocking
568+
# immediately can see fewer locks than were just acquired. Locked requests are excluded from the
569+
# queue head, so poll `list_head` until none of the locked requests reappear there, rather than
570+
# guessing a fixed sleep.
571+
async def all_locks_visible() -> bool:
572+
head = await maybe_await(rq_client.list_head(limit=5))
573+
return isinstance(head, RequestQueueHead) and locked_ids.isdisjoint(item.id for item in head.items)
574+
575+
await poll_until_condition(all_locks_visible, timeout=30, poll_interval=1)
568576

569577
# Unlock all requests
570578
unlock_response = await maybe_await(rq_client.unlock_requests())

0 commit comments

Comments
 (0)