Skip to content

Commit

Permalink
Fix CLIENAT KILL MAXAGE test timing issue
Browse files Browse the repository at this point in the history
This test fails occasionally:
```
*** [err]: CLIENT KILL maxAGE will kill old clients in tests/unit/introspection.tcl
Expected 2 == 1 (context: type eval line 14 cmd {assert {$res == 1}} proc ::test)
```

This test is very likely to do a false positive if the execute time
takes longer than the max age, for example, if the execution time
between sleep and kill exceeds 1s, rd2 will also be killed due to
the max age.

The test can adjust the order of execution statements to increase
the probability of passing, but this is still will be a timing issue
in some slow machines, so decided give it a few more chances.

The test was introduced in redis#12299.
  • Loading branch information
enjoy-binbin committed Feb 11, 2024
1 parent 676f27a commit 9b6cee1
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion tests/unit/introspection.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ start_server {tags {"introspection"}} {
}

test {CLIENT KILL maxAGE will kill old clients} {
# This test is very likely to do a false positive if the execute time
# takes longer than the max age, so give it a few more chances.
for {set i 0} {$i < 10} {incr i} {

set rd1 [redis_deferring_client]
r debug sleep 2
set rd2 [redis_deferring_client]
Expand All @@ -51,7 +55,18 @@ start_server {tags {"introspection"}} {

# Should kill rd1 but not rd2
set res [r client kill user dummy maxage 1]
assert {$res == 1}
if {$res == 1} {
break
} else {
# Clean up and try again next time
$rd1 close
$rd2 close
}

} ;# for

if {$::verbose} { puts "CLIENT KILL maxAGE will kill old clients test attempts: $i" }
assert_equal $res 1

# rd2 should still be connected
$rd2 ping
Expand Down

0 comments on commit 9b6cee1

Please sign in to comment.