Fix test and improve assert_replication_stream print the whole stream (#11793)

This PR has two parts:

1. Fix flaky test case, the previous tests set a lot of volatile keys,
it injects an unexpected DEL command into the replication stream during
the later test, causing it to fail. Add a flushall to avoid it.

2. Improve assert_replication_stream, now it can print the whole stream
rather than just the failing line.
This commit is contained in:
Binbin 2023-03-09 04:39:54 +08:00 committed by GitHub
parent 312654d5be
commit a7c9e5053a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 3 deletions

View File

@ -24,9 +24,11 @@ proc assert_no_match {pattern value} {
}
}
proc assert_match {pattern value {detail ""}} {
proc assert_match {pattern value {detail ""} {context ""}} {
if {![string match $pattern $value]} {
set context "(context: [info frame -1])"
if {$context eq ""} {
set context "(context: [info frame -1])"
}
error "assertion:Expected '$value' to match '$pattern' $context $detail"
}
}

View File

@ -857,9 +857,22 @@ proc read_from_replication_stream {s} {
}
proc assert_replication_stream {s patterns} {
set errors 0
set values_list {}
set patterns_list {}
for {set j 0} {$j < [llength $patterns]} {incr j} {
assert_match [lindex $patterns $j] [read_from_replication_stream $s]
set pattern [lindex $patterns $j]
lappend patterns_list $pattern
set value [read_from_replication_stream $s]
lappend values_list $value
if {![string match $pattern $value]} { incr errors }
}
if {$errors == 0} { return }
set context [info frame -1]
close_replication_stream $s ;# for fast exit
assert_match $patterns_list $values_list "" $context
}
proc close_replication_stream {s} {

View File

@ -628,6 +628,9 @@ start_server {tags {"expire"}} {
} {-1} {needs:debug}
test {GETEX propagate as to replica as PERSIST, DEL, or nothing} {
# In the above tests, many keys with random expiration times are set, flush
# the DBs to avoid active expiry kicking in and messing the replication streams.
r flushall
set repl [attach_to_replication_stream]
r set foo bar EX 100
r getex foo PERSIST