Skip to content

Commit 4ccaebb

Browse files
committed
Relax timing constraints.
1 parent 1a3fe1c commit 4ccaebb

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

run_test_loop.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
echo "Running test 100 times to detect flakes..."
4+
failures=0
5+
for i in $(seq 1 100); do
6+
if ! cargo test test_concurrent_gc_and_access --lib -- --nocapture --test-threads=1 2>&1 | grep -q "test result: ok"; then
7+
echo "FAILED on run $i"
8+
failures=$((failures + 1))
9+
fi
10+
if [ $((i % 10)) -eq 0 ]; then
11+
echo "Completed $i runs, failures: $failures"
12+
fi
13+
done
14+
echo "Total failures: $failures/100"

src/common/ttl_map.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ mod tests {
368368
// All entries expired
369369
}
370370

371-
// assert_eventually checks a condition every 10ms for a maximum of timeout
371+
// assert_eventually checks a condition every 2ms for a maximum of timeout
372372
async fn assert_eventually<F>(assertion: F, timeout: Duration)
373373
where
374374
F: Fn() -> bool,
@@ -378,17 +378,16 @@ mod tests {
378378
if assertion() {
379379
return;
380380
}
381-
tokio::time::sleep(Duration::from_millis(10)).await;
381+
tokio::time::sleep(Duration::from_millis(2)).await;
382382
}
383383
panic!("Assertion failed within {:?}", timeout);
384384
}
385385

386386
#[tokio::test(flavor = "multi_thread", worker_threads = 8)]
387-
#[ignore] // the test is flaky, uncomment once flakyness is solved
388387
async fn test_concurrent_gc_and_access() {
389388
let ttl_map = TTLMap::<String, i32>::try_new(TTLMapConfig {
390-
ttl: Duration::from_millis(10),
391-
tick: Duration::from_millis(2),
389+
ttl: Duration::from_millis(50),
390+
tick: Duration::from_millis(10),
392391
})
393392
.unwrap();
394393

@@ -421,7 +420,11 @@ mod tests {
421420
handle.await.unwrap();
422421
}
423422

424-
assert_eventually(|| ttl_map.data.is_empty(), Duration::from_millis(20)).await;
423+
// Allow time for pending bucket registration messages to be processed
424+
tokio::time::sleep(Duration::from_millis(10)).await;
425+
426+
// Wait for GC to clear all entries (5× TTL to account for scheduling delays)
427+
assert_eventually(|| ttl_map.data.is_empty(), Duration::from_millis(250)).await;
425428
}
426429

427430
#[tokio::test]

0 commit comments

Comments
 (0)