Commit 5080e625 authored by antirez's avatar antirez
Browse files

Redis test: scripting EVALSHA replication test more reliable.

A new primitive wait_for_condition was introduced in the scripting
engine that makes waiting for events simpler, so that it is simpler to
write tests that are more resistant to timing issues.
parent d9237055
...@@ -3,6 +3,10 @@ set ::num_passed 0 ...@@ -3,6 +3,10 @@ set ::num_passed 0
set ::num_failed 0 set ::num_failed 0
set ::tests_failed {} set ::tests_failed {}
proc fail {msg} {
error "assertion:$msg"
}
proc assert {condition} { proc assert {condition} {
if {![uplevel 1 [list expr $condition]]} { if {![uplevel 1 [list expr $condition]]} {
error "assertion:Expected condition '$condition' to be true ([uplevel 1 [list subst -nocommands $condition]])" error "assertion:Expected condition '$condition' to be true ([uplevel 1 [list subst -nocommands $condition]])"
...@@ -44,6 +48,19 @@ proc assert_type {type key} { ...@@ -44,6 +48,19 @@ proc assert_type {type key} {
assert_equal $type [r type $key] assert_equal $type [r type $key]
} }
# Wait for the specified condition to be true, with the specified number of
# max retries and delay between retries. Otherwise the 'elsescript' is
# executed.
proc wait_for_condition {maxtries delay e _else_ elsescript} {
while {[incr maxtries -1] >= 0} {
if {[uplevel 1 expr $e]} break
after $delay
}
if {$maxtries == -1} {
uplevel 1 $elsescript
}
}
# Test if TERM looks like to support colors # Test if TERM looks like to support colors
proc color_term {} { proc color_term {} {
expr {[info exists ::env(TERM)] && [string match *xterm* $::env(TERM)]} expr {[info exists ::env(TERM)] && [string match *xterm* $::env(TERM)]}
......
...@@ -327,10 +327,12 @@ start_server {tags {"scripting repl"}} { ...@@ -327,10 +327,12 @@ start_server {tags {"scripting repl"}} {
r evalsha ae3477e27be955de7e1bc9adfdca626b478d3cb2 0 r evalsha ae3477e27be955de7e1bc9adfdca626b478d3cb2 0
} {2} } {2}
if {$::valgrind} {after 2000} else {after 100}
test {If EVALSHA was replicated as EVAL the slave should be ok} { test {If EVALSHA was replicated as EVAL the slave should be ok} {
r -1 get x wait_for_condition 50 100 {
} {2} [r -1 get x] eq {2}
} else {
fail "Expected 2 in x, but value is '[r -1 get x]'"
}
}
} }
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment