From 7c429b64a3a2839abe86b35938918983af0d6b2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Mon, 14 Sep 2026 19:11:18 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=20shared=20rate-limit=20tes?= =?UTF-8?q?ts=20wait=20a=20second=20sync=20round?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Each limiter's fold is its own statement. One round leaves the first finisher with a stale remote total (CI: expected 0 admits, got 3). Local: cargo nextest run --no-fail-fast → 1373 passed. rate_limit binary ×3 passed. --- tests/rate_limit.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/rate_limit.rs b/tests/rate_limit.rs index 4964841..85bff3c 100644 --- a/tests/rate_limit.rs +++ b/tests/rate_limit.rs @@ -432,7 +432,7 @@ async fn sync_round() { tokio::task::yield_now().await; tokio::time::advance(Duration::from_secs(RATE_SYNC_INTERVAL_SECS)).await; tokio::time::resume(); - tokio::time::sleep(Duration::from_millis(750)).await; + tokio::time::sleep(Duration::from_millis(2000)).await; tokio::time::pause(); } @@ -489,8 +489,9 @@ async fn a_restarted_process_inherits_the_windows_spend() { let spent = admits(&a, "user:a", 6) + admits(&b, "user:a", 6); assert_eq!(spent, 12, "each process starts on its own local budget"); - // From the first sync on, the shared total is what binds: neither limiter - // admits anything more in this window, whatever the interleaving was. + // Two rounds: each limiter's fold is its own statement, so the process + // that landed first only learns the other's spend on the next tick. + sync_round().await; sync_round().await; assert_eq!( admits(&a, "user:a", 6) + admits(&b, "user:a", 6), @@ -512,6 +513,7 @@ async fn a_process_that_never_admitted_still_learns_the_budget_is_gone() { assert_eq!(admits(&b, "user:a", 1), 1); assert_eq!(admits(&a, "user:a", 3), 3); sync_round().await; + sync_round().await; assert_eq!( admits(&b, "user:a", 3),