Stop the rate-limit tests racing the derivation they trigger - #931
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
WalkthroughRate-limiting tests for outer and hidden volumes now use bounded retry loops and assert that at least one unlock attempt returns ChangesRate-limit test stabilization
Estimated code review effort: 1 (Trivial) | ~3 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
build (macos-latest)failed on main withtest_rate_limiting_outerasserting that an unlock attempt was refused when it was not. The job does not run on pull requests, so this only appears after merge.Not a regression from the commit it failed on, which touched only keep-mobile while this test lives in keep-core. It is a timing race the test has always had.
The backoff is measured from the last recorded failure and doubles past the free allowance, so one, two, four seconds and so on. Each attempt costs an Argon2 derivation, and that cost is constant. The test spent its five free attempts, then made three rapid ones and asserted the third was refused, at which point the required wait was four seconds. On a runner where a single derivation takes longer than that, the window has already elapsed by the time the next attempt arrives, every attempt is allowed, and the assertion fails. The existing comment anticipated exactly this and picked a fixed number of attempts, which cannot be enough for an arbitrarily slow machine.
Both affected tests now keep attempting until one is refused, bounded so a real regression fails rather than loops. This is not a weaker assertion: the delay grows exponentially while the derivation cost does not, so the backoff overtakes it within a couple of attempts on any machine. It removes the dependency on the runner being fast rather than papering over the failure.
The combined-unlock test in the same module shares the shape but asserts differently and was already passing; it is left alone rather than changed speculatively.
Test plan
All three rate-limit tests pass locally, and the full
cargo test -p keep-core --libsuite is clean at 386 tests.cargo clippy --all-targets -- -D warningsandcargo fmt --checkclean.Falsified rather than assumed: with the rate-limit check stubbed to always allow, all three fail. So the loop still catches the defect the test exists for; it just no longer races the derivation.
The original failure cannot be reproduced on this machine, because reproducing it requires an Argon2 derivation slower than the four-second window. The mechanism is established from the backoff computation and the failing assertion rather than from a local repro, and the fix removes the dependency on that timing entirely rather than tuning it.
Summary by CodeRabbit