Problem
The test test_accept_exponential_backoff_doubles_and_caps() in src/server/config/tests.rs (lines 249-295) uses wall-clock sleeps which introduce flakiness and slow down the test suite.
Solution
Replace the wall-clock sleep approach with deterministic assertion of the backoff schedule by extracting a pure function that computes the backoff sequence.
Example Refactor
/// Behaviour test verifying exponential delay doubling and capping (pure logic).
#[test]
fn test_accept_exponential_backoff_doubles_and_caps() {
use std::time::Duration;
let initial = Duration::from_millis(10);
let max = Duration::from_millis(80);
let attempts = 5usize;
let mut backoff = initial;
let mut sequence = Vec::with_capacity(attempts);
for _ in 0..attempts {
sequence.push(backoff);
backoff = std::cmp::min(backoff.saturating_mul(2), max);
}
let expected = [
initial,
std::cmp::min(initial * 2, max),
std::cmp::min(initial * 4, max),
std::cmp::min(initial * 8, max),
max,
];
assert_eq!(&sequence[..], &expected);
}
Benefits
- Eliminates test flakiness from timing-dependent assertions
- Significantly faster test execution
- More deterministic and reliable test behaviour
- Validates the core doubling-and-capping logic without timing concerns
Backlinks
Problem
The test
test_accept_exponential_backoff_doubles_and_caps()insrc/server/config/tests.rs(lines 249-295) uses wall-clock sleeps which introduce flakiness and slow down the test suite.Solution
Replace the wall-clock sleep approach with deterministic assertion of the backoff schedule by extracting a pure function that computes the backoff sequence.
Example Refactor
Benefits
Backlinks