From 3ddf6a4b487f66aac5b326d60b59937bec0c2afe Mon Sep 17 00:00:00 2001 From: Madelyn Olson Date: Wed, 16 Sep 2026 05:01:29 +0000 Subject: [PATCH] Test: derive forkless bgsave TTL deadlines from when each EXPIRE ran 'TTL expiration during forkless bgsave' issued 1200 synchronous EXPIRE round trips but computed every expiry deadline from a timestamp taken before that loop began, so its model of when key i dies lagged reality by however long the loop took. For keys where i % 10 == 0 the built-in slack was exactly one second, so any environment slower than about 0.9 ms per round trip failed the 'must be gone' assertion. Record each key's deadline as its own EXPIREs are issued, and re-sample the clock per key in the verification loop instead of once per outer pass over up to 1200 EXISTS calls. Test-only. Upstream: valkey-io/valkey#4611 Signed-off-by: Madelyn Olson --- tests/integration/rdb.tcl | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/tests/integration/rdb.tcl b/tests/integration/rdb.tcl index c74ea92094c..eb0c10b6f61 100644 --- a/tests/integration/rdb.tcl +++ b/tests/integration/rdb.tcl @@ -1011,10 +1011,15 @@ start_server {overrides {forkless-infrastructure-enabled yes save ""}} { set num_keys 100 createComplexDatasetForVerification r $num_keys - # Set TTLs on all keys - key i expires in (i/10 + 1) seconds - set start_time [clock milliseconds] + # Set TTLs on all keys - key i expires in (i/10 + 1) seconds. + # Record each key's deadline as its own EXPIREs are issued. This loop is + # 1200 synchronous round trips and takes seconds on a slow machine, so a + # single pre-loop timestamp does not describe when key i actually dies. + # Sampling before the 12 EXPIREs keeps deadline($i) at or below every + # real deadline, which is the safe direction for both checks below. for {set i 0} {$i < $num_keys} {incr i} { set ttl [expr {$i/10 + 1}] + set deadline($i) [expr {[clock milliseconds] + $ttl * 1000}] foreach prefix {before int lst set zset hash hll bits geo geo_set stream iset} { r expire ${prefix}_${i} $ttl } @@ -1039,11 +1044,13 @@ start_server {overrides {forkless-infrastructure-enabled yes save ""}} { } while {[llength $verified] > 0} { - set elapsed_time [expr {([clock milliseconds] - $start_time) / 1000.0}] - foreach i $verified { + # Re-sample per key: a single sample per outer pass goes stale + # across the up to 1200 EXISTS calls issued below it. + set now [clock milliseconds] + # If not yet expired, verify all data types exist - if {$elapsed_time < [expr {$i/10.0}]} { + if {$now + 1000 < $deadline($i)} { assert_equal [r exists before_${i}] 1 assert_equal [r exists int_${i}] 1 assert_equal [r exists lst_${i}] 1 @@ -1059,7 +1066,7 @@ start_server {overrides {forkless-infrastructure-enabled yes save ""}} { } # If expired for more than 2 seconds, verify all data types are gone - if {$elapsed_time > [expr {$i/10.0 + 2}]} { + if {$now > $deadline($i) + 2000} { assert_equal [r exists before_${i}] 0 assert_equal [r exists int_${i}] 0 assert_equal [r exists lst_${i}] 0