summaryrefslogtreecommitdiff
path: root/tests/support/test.tcl
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2012-04-26 11:16:52 +0200
committerantirez <antirez@gmail.com>2012-04-26 11:16:52 +0200
commit5080e625d31e5132f952c5132e69aa65c6c2b383 (patch)
tree22c16785fe4c6a66d08be72a8ab7d0ffdf1b291a /tests/support/test.tcl
parentd9237055baddbc41d6832ef5e6a516feb738eb95 (diff)
downloadredis-5080e625d31e5132f952c5132e69aa65c6c2b383.tar.gz
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.
Diffstat (limited to 'tests/support/test.tcl')
-rw-r--r--tests/support/test.tcl17
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/support/test.tcl b/tests/support/test.tcl
index f66e54b87..91ab8117b 100644
--- a/tests/support/test.tcl
+++ b/tests/support/test.tcl
@@ -3,6 +3,10 @@ set ::num_passed 0
set ::num_failed 0
set ::tests_failed {}
+proc fail {msg} {
+ error "assertion:$msg"
+}
+
proc assert {condition} {
if {![uplevel 1 [list expr $condition]]} {
error "assertion:Expected condition '$condition' to be true ([uplevel 1 [list subst -nocommands $condition]])"
@@ -44,6 +48,19 @@ proc assert_type {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
proc color_term {} {
expr {[info exists ::env(TERM)] && [string match *xterm* $::env(TERM)]}