Fix CLIENAT KILL MAXAGE test timing issue (#13047)

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 #12299.
This commit is contained in:
Binbin 2024-02-12 14:11:33 +08:00 committed by GitHub
parent 676f27acb0
commit 8eeece4ab3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 31 additions and 11 deletions

View File

@ -23,6 +23,7 @@ jobs:
run: | run: |
./runtest \ ./runtest \
--host 127.0.0.1 --port 6379 \ --host 127.0.0.1 --port 6379 \
--verbose \
--tags -slow --tags -slow
- name: Archive redis log - name: Archive redis log
if: ${{ failure() }} if: ${{ failure() }}
@ -49,6 +50,7 @@ jobs:
run: | run: |
./runtest \ ./runtest \
--host 127.0.0.1 --port 6379 \ --host 127.0.0.1 --port 6379 \
--verbose \
--cluster-mode \ --cluster-mode \
--tags -slow --tags -slow
- name: Archive redis log - name: Archive redis log
@ -73,6 +75,7 @@ jobs:
run: | run: |
./runtest \ ./runtest \
--host 127.0.0.1 --port 6379 \ --host 127.0.0.1 --port 6379 \
--verbose \
--tags "-slow -needs:debug" --tags "-slow -needs:debug"
- name: Archive redis log - name: Archive redis log
if: ${{ failure() }} if: ${{ failure() }}

View File

@ -39,19 +39,36 @@ start_server {tags {"introspection"}} {
} }
test {CLIENT KILL maxAGE will kill old clients} { test {CLIENT KILL maxAGE will kill old clients} {
set rd1 [redis_deferring_client] # This test is very likely to do a false positive if the execute time
r debug sleep 2 # takes longer than the max age, so give it a few more chances. Go with
set rd2 [redis_deferring_client] # 3 retries of increasing sleep_time, i.e. start with 2s, then go 4s, 8s.
set sleep_time 2
for {set i 0} {$i < 3} {incr i} {
set rd1 [redis_deferring_client]
r debug sleep $sleep_time
set rd2 [redis_deferring_client]
r acl setuser dummy on nopass +ping
$rd1 auth dummy ""
$rd1 read
$rd2 auth dummy ""
$rd2 read
r acl setuser dummy on nopass +ping # Should kill rd1 but not rd2
$rd1 auth dummy "" set max_age [expr $sleep_time / 2]
$rd1 read set res [r client kill user dummy maxage $max_age]
$rd2 auth dummy "" if {$res == 1} {
$rd2 read break
} else {
# Clean up and try again next time
set sleep_time [expr $sleep_time * 2]
$rd1 close
$rd2 close
}
# Should kill rd1 but not rd2 } ;# for
set res [r client kill user dummy maxage 1]
assert {$res == 1} if {$::verbose} { puts "CLIENT KILL maxAGE will kill old clients test attempts: $i" }
assert_equal $res 1
# rd2 should still be connected # rd2 should still be connected
$rd2 ping $rd2 ping