Fix timing issue in sub-second expires test (#9821)

The `PEXPIRE/PSETEX/PEXPIREAT can set sub-second expires` test is
a very time sensitive test, it used to occasionally fail on MacOS.

It will perform there internal tests in a loop, as long as one
fails, it will try to excute again in the next loop.

oranagra suggested that we can split it into three individual tests,
so that if one fails, we do not need to retry the others. And maybe
it will increase the chances of success dramatically.

Each is executed 500 times, and the number of retries is collected:
```
PSETEX, total: 500, sum: 745, min: 0, max: 13, avg: 1.49

PEXPIRE, total: 500, sum: 575, min: 0, max: 16, avg: 1.15

PEXPIREAT, total: 500, sum: 0, min: 0, max: 0, avg: 0.0

ALL(old_way), total: 500, sum: 8090, min: 0, max: 138, avg: 16.18
```

And we can see the threshold is very low.
Splitting the test also makes the code better to maintain.

Co-authored-by: Oran Agra <oran@redislabs.com>
This commit is contained in:
Binbin 2021-11-22 14:39:27 +08:00 committed by GitHub
parent 183b90a625
commit 698b577413
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 27 additions and 14 deletions

View File

@ -91,20 +91,27 @@ start_server {tags {"expire"}} {
list $a $b list $a $b
} {somevalue {}} } {somevalue {}}
test {PEXPIRE/PSETEX/PEXPIREAT can set sub-second expires} { test "PSETEX can set sub-second expires" {
# This test is very likely to do a false positive if the # This test is very likely to do a false positive if the server is
# server is under pressure, so if it does not work give it a few more # under pressure, so if it does not work give it a few more chances.
# chances.
for {set j 0} {$j < 50} {incr j} { for {set j 0} {$j < 50} {incr j} {
r del x r del x
r del y
r del z
r psetex x 100 somevalue r psetex x 100 somevalue
after 80 after 80
set a [r get x] set a [r get x]
after 120 after 120
set b [r get x] set b [r get x]
if {$a eq {somevalue} && $b eq {}} break
}
if {$::verbose} { puts "PSETEX sub-second expire test attempts: $j" }
list $a $b
} {somevalue {}}
test "PEXPIRE can set sub-second expires" {
# This test is very likely to do a false positive if the server is
# under pressure, so if it does not work give it a few more chances.
for {set j 0} {$j < 50} {incr j} {
r set x somevalue r set x somevalue
r pexpire x 100 r pexpire x 100
after 80 after 80
@ -112,6 +119,16 @@ start_server {tags {"expire"}} {
after 120 after 120
set d [r get x] set d [r get x]
if {$c eq {somevalue} && $d eq {}} break
}
if {$::verbose} { puts "PEXPIRE sub-second expire test attempts: $j" }
list $c $d
} {somevalue {}}
test "PEXPIREAT can set sub-second expires" {
# This test is very likely to do a false positive if the server is
# under pressure, so if it does not work give it a few more chances.
for {set j 0} {$j < 50} {incr j} {
r set x somevalue r set x somevalue
set now [r time] set now [r time]
r pexpireat x [expr ([lindex $now 0]*1000)+([lindex $now 1]/1000)+200] r pexpireat x [expr ([lindex $now 0]*1000)+([lindex $now 1]/1000)+200]
@ -120,15 +137,11 @@ start_server {tags {"expire"}} {
after 220 after 220
set f [r get x] set f [r get x]
if {$a eq {somevalue} && $b eq {} && if {$e eq {somevalue} && $f eq {}} break
$c eq {somevalue} && $d eq {} &&
$e eq {somevalue} && $f eq {}} break
} }
if {$::verbose} { if {$::verbose} { puts "PEXPIREAT sub-second expire test attempts: $j" }
puts "sub-second expire test attempts: $j" list $e $f
} } {somevalue {}}
list $a $b $c $d $e $f
} {somevalue {} somevalue {} somevalue {}}
test {TTL returns time to live in seconds} { test {TTL returns time to live in seconds} {
r del x r del x