Skip to content

Commit 3e28576

Browse files
vdusekclaude
andcommitted
fix: Remove call_with_exp_backoff from while-not loop conditions
Using call_with_exp_backoff in `while not is_empty/is_finished` loop conditions caused infinite loops in shared mode — the backoff retried 3 times (7s) per iteration even when the queue legitimately had items, leading to 1800s+ timeouts on large batches. Replaced with walrus operator `while request := await call_with_exp_backoff(fetch_next_request)` pattern in test_large_batch_operations, test_persistence_across_operations, and test_concurrent_processing_simulation. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent f20c29f commit 3e28576

File tree

1 file changed

+7
-20
lines changed

1 file changed

+7
-20
lines changed

tests/integration/test_request_queue.py

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -592,12 +592,7 @@ async def test_large_batch_operations(
592592
# Process all in chunks to test performance.
593593
processed_count = 0
594594

595-
while not await call_with_exp_backoff(rq.is_empty, rq_access_mode=rq_access_mode):
596-
next_request = await call_with_exp_backoff(rq.fetch_next_request, rq_access_mode=rq_access_mode)
597-
598-
# The RQ is_empty should ensure we don't get None
599-
assert next_request is not None, f'next_request={next_request}'
600-
595+
while next_request := await call_with_exp_backoff(rq.fetch_next_request, rq_access_mode=rq_access_mode):
601596
await rq.mark_request_as_handled(next_request)
602597
processed_count += 1
603598

@@ -707,13 +702,9 @@ async def test_persistence_across_operations(
707702

708703
# Process remaining.
709704
remaining_processed = 0
710-
while not await call_with_exp_backoff(rq.is_finished, rq_access_mode=rq_access_mode):
711-
next_request = await call_with_exp_backoff(rq.fetch_next_request, rq_access_mode=rq_access_mode)
712-
if next_request:
713-
remaining_processed += 1
714-
await rq.mark_request_as_handled(next_request)
715-
else:
716-
break
705+
while next_request := await call_with_exp_backoff(rq.fetch_next_request, rq_access_mode=rq_access_mode):
706+
remaining_processed += 1
707+
await rq.mark_request_as_handled(next_request)
717708

718709
Actor.log.info(f'Processed {remaining_processed} remaining requests')
719710
is_finished = await call_with_exp_backoff(rq.is_finished, rq_access_mode=rq_access_mode)
@@ -1385,13 +1376,9 @@ async def worker() -> int:
13851376
assert total_after_workers == 20
13861377

13871378
remaining_count = 0
1388-
while not await call_with_exp_backoff(rq.is_finished, rq_access_mode='shared'):
1389-
request = await call_with_exp_backoff(rq.fetch_next_request, rq_access_mode='shared')
1390-
if request:
1391-
remaining_count += 1
1392-
await rq.mark_request_as_handled(request)
1393-
else:
1394-
break
1379+
while request := await call_with_exp_backoff(rq.fetch_next_request, rq_access_mode='shared'):
1380+
remaining_count += 1
1381+
await rq.mark_request_as_handled(request)
13951382

13961383
final_handled = await rq.get_handled_count()
13971384
final_total = await rq.get_total_count()

0 commit comments

Comments
 (0)