forge
Explore
Log in

Don't you dare go Hollow

Shared rate-limit tests wait a second sync round

Browse files at this commit

7c429b64a3a2839abe86b35938918983af0d6b2aAhmet Kaan GümüşParent: fa1529a
  • fix
    • shared rate-limit tests wait a second sync round
Show full message
🐛 fix: shared rate-limit tests wait a second sync round

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.rsmodified+5 -3
@@ -432,7 +432,7 @@ async fn sync_round() {
432432 tokio::task::yield_now().await;
433433 tokio::time::advance(Duration::from_secs(RATE_SYNC_INTERVAL_SECS)).await;
434434 tokio::time::resume();
435- tokio::time::sleep(Duration::from_millis(750)).await;
435+ tokio::time::sleep(Duration::from_millis(2000)).await;
436436 tokio::time::pause();
437437 }
438438
@@ -489,8 +489,9 @@ async fn a_restarted_process_inherits_the_windows_spend() {
489489 let spent = admits(&a, "user:a", 6) + admits(&b, "user:a", 6);
490490 assert_eq!(spent, 12, "each process starts on its own local budget");
491491
492- // From the first sync on, the shared total is what binds: neither limiter
493- // admits anything more in this window, whatever the interleaving was.
492+ // Two rounds: each limiter's fold is its own statement, so the process
493+ // that landed first only learns the other's spend on the next tick.
494+ sync_round().await;
494495 sync_round().await;
495496 assert_eq!(
496497 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() {
512513 assert_eq!(admits(&b, "user:a", 1), 1);
513514 assert_eq!(admits(&a, "user:a", 3), 3);
514515 sync_round().await;
516+ sync_round().await;
515517
516518 assert_eq!(
517519 admits(&b, "user:a", 3),