From a76717692b818f857585e361ea18fe54d420e89c Mon Sep 17 00:00:00 2001 From: Matt Tanous Date: Sat, 10 Oct 2026 01:19:12 -0400 Subject: [PATCH] test(batch): allow for tokens refilled before the rate limit check reads the counts On a slow runner the counts were read after another token refilled, so a fourth legitimate claim failed the early check. The per-job start-time assertions still verify the rate limit itself. Co-Authored-By: Claude Opus 5.5 --- tests/batch_dequeue_tests.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/batch_dequeue_tests.rs b/tests/batch_dequeue_tests.rs index 20f3865..0e8d3da 100644 --- a/tests/batch_dequeue_tests.rs +++ b/tests/batch_dequeue_tests.rs @@ -821,9 +821,15 @@ mod worker { tokio::time::sleep(Duration::from_millis(5)).await; } let counts = queue.get_job_counts_by_status(&queue_name).await.unwrap(); + // Tokens refill one every 333ms, so by the time the counts are read (late on a + // slow runner) a few more claims may be legitimate. + let refilled = (began.elapsed().as_millis() / 333) as usize; + let allowed = (3 + refilled).min(JOBS); assert!( - counts.get("Pending").copied().unwrap_or(0) >= (JOBS - 3) as u64, - "a batch claimed more jobs than it had rate limit tokens: {counts:?}" + counts.get("Pending").copied().unwrap_or(0) >= (JOBS - allowed) as u64, + "a batch claimed more jobs than it had rate limit tokens \ + ({allowed} allowed after {:?}): {counts:?}", + began.elapsed() ); wait_for_status(