From 06b577aad01d132b0792581a3f1235bc84a32026 Mon Sep 17 00:00:00 2001 From: Binbin Date: Mon, 28 Nov 2022 19:03:55 +0800 Subject: [PATCH] Fix replication on expired key test timing issue, give it more chances (#11548) In replica, the key expired before master's `INCR` was arrived, so INCR creates a new key in the replica and the test failed. ``` *** [err]: Replication of an expired key does not delete the expired key in tests/integration/replication-4.tcl Expected '0' to be equal to '1' (context: type eval line 13 cmd {assert_equal 0 [$slave exists k]} proc ::test) ``` This test is very likely to do a false positive if the `wait_for_ofs_sync` takes longer than the expiration time, so give it a few more chances. The test was introduced in #9572. --- tests/integration/replication-4.tcl | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/tests/integration/replication-4.tcl b/tests/integration/replication-4.tcl index 9f4281f7cd..d7a8b92a6f 100644 --- a/tests/integration/replication-4.tcl +++ b/tests/integration/replication-4.tcl @@ -122,19 +122,35 @@ start_server {tags {"repl external:skip"}} { } test {Replication of an expired key does not delete the expired key} { + # This test is very likely to do a false positive if the wait_for_ofs_sync + # takes longer than the expiration time, so give it a few more chances. + # Go with 5 retries of increasing timeout, i.e. start with 500ms, then go + # to 1000ms, 2000ms, 4000ms, 8000ms. + set px_ms 500 + for {set i 0} {$i < 5} {incr i} { + + wait_for_ofs_sync $master $slave $master debug set-active-expire 0 - $master set k 1 ex 1 + $master set k 1 px $px_ms wait_for_ofs_sync $master $slave exec kill -SIGSTOP [srv 0 pid] $master incr k - after 1001 + after [expr $px_ms + 1] # Stopping the replica for one second to makes sure the INCR arrives # to the replica after the key is logically expired. exec kill -SIGCONT [srv 0 pid] wait_for_ofs_sync $master $slave # Check that k is logically expired but is present in the replica. - assert_equal 0 [$slave exists k] - $slave debug object k ; # Raises exception if k is gone. + set res [$slave exists k] + set errcode [catch {$slave debug object k} err] ; # Raises exception if k is gone. + if {$res == 0 && $errcode == 0} { break } + set px_ms [expr $px_ms * 2] + + } ;# for + + if {$::verbose} { puts "Replication of an expired key does not delete the expired key test attempts: $i" } + assert_equal $res 0 + assert_equal $errcode 0 } } }