diff options
author | antirez <antirez@gmail.com> | 2012-04-30 11:47:47 +0200 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2012-04-30 11:47:47 +0200 |
commit | 28500d193f8c9db99def02ff409620b29e731c8c (patch) | |
tree | d437a41a2663e2c4fecd8526f5ac5dff697180be /tests | |
parent | 63bae7c55382985b571457d01223bd2856856db9 (diff) | |
download | redis-28500d193f8c9db99def02ff409620b29e731c8c.tar.gz |
Testing framework fixes and improvements backported from 2.6.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/support/redis.tcl | 10 | ||||
-rw-r--r-- | tests/support/server.tcl | 37 | ||||
-rw-r--r-- | tests/support/test.tcl | 17 | ||||
-rw-r--r-- | tests/support/util.tcl | 4 |
4 files changed, 52 insertions, 16 deletions
diff --git a/tests/support/redis.tcl b/tests/support/redis.tcl index 4f8ac485d..99415b640 100644 --- a/tests/support/redis.tcl +++ b/tests/support/redis.tcl @@ -142,9 +142,15 @@ proc ::redis::redis_multi_bulk_read fd { set count [redis_read_line $fd] if {$count == -1} return {} set l {} + set err {} for {set i 0} {$i < $count} {incr i} { - lappend l [redis_read_reply $fd] + if {[catch { + lappend l [redis_read_reply $fd] + } e] && $err eq {}} { + set err $e + } } + if {$err ne {}} {return -code error $err} return $l } @@ -160,7 +166,7 @@ proc ::redis::redis_read_reply fd { - {return -code error [redis_read_line $fd]} $ {redis_bulk_read $fd} * {redis_multi_bulk_read $fd} - default {return -code error "Bad protocol, $type as reply type byte"} + default {return -code error "Bad protocol, '$type' as reply type byte"} } } diff --git a/tests/support/server.tcl b/tests/support/server.tcl index c2d7132d2..35c1cb870 100644 --- a/tests/support/server.tcl +++ b/tests/support/server.tcl @@ -2,13 +2,14 @@ set ::global_overrides {} set ::tags {} set ::valgrind_errors {} -proc error_and_quit {config_file error} { - puts "!!COULD NOT START REDIS-SERVER\n" - puts "CONFIGURATION:" - puts [exec cat $config_file] - puts "\nERROR:" - puts [string trim $error] - exit 1 +proc start_server_error {config_file error} { + set err {} + append err "Cant' start the Redis server\n" + append err "CONFIGURATION:" + append err [exec cat $config_file] + append err "\nERROR:" + append err [string trim $error] + send_data_packet $::test_server_fd err $err } proc check_valgrind_errors stderr { @@ -16,7 +17,7 @@ proc check_valgrind_errors stderr { set buf [read $fd] close $fd - if {![regexp -- {ERROR SUMMARY: 0 errors} $buf] || + if {[regexp -- { at 0x} $buf] || (![regexp -- {definitely lost: 0 bytes} $buf] && ![regexp -- {no leaks are possible} $buf])} { send_data_packet $::test_server_fd err "Valgrind error: $buf\n" @@ -45,11 +46,16 @@ proc kill_server config { } # kill server and wait for the process to be totally exited + catch {exec kill $pid} while {[is_alive $config]} { - if {[incr wait 10] % 1000 == 0} { + incr wait 10 + + if {$wait >= 5000} { + puts "Forcing process $pid to exit..." + catch {exec kill -KILL $pid} + } elseif {$wait % 1000 == 0} { puts "Waiting for process $pid to exit..." } - catch {exec kill $pid} after 10 } @@ -175,14 +181,14 @@ proc start_server {options {code undefined}} { set stderr [format "%s/%s" [dict get $config "dir"] "stderr"] if {$::valgrind} { - exec valgrind --suppressions=src/valgrind.sup src/redis-server $config_file > $stdout 2> $stderr & + exec valgrind --suppressions=src/valgrind.sup --show-reachable=no --show-possibly-lost=no --leak-check=full src/redis-server $config_file > $stdout 2> $stderr & } else { exec src/redis-server $config_file > $stdout 2> $stderr & } # check that the server actually started # ugly but tries to be as fast as possible... - set retrynum 100 + if {$::valgrind} {set retrynum 1000} else {set retrynum 100} set serverisup 0 if {$::verbose} { @@ -209,7 +215,10 @@ proc start_server {options {code undefined}} { } if {!$serverisup} { - error_and_quit $config_file [exec cat $stderr] + set err {} + append err [exec cat $stdout] "\n" [exec cat $stderr] + start_server_error $config_file $err + return } # find out the pid @@ -243,7 +252,7 @@ proc start_server {options {code undefined}} { while 1 { # check that the server actually started and is ready for connections - if {[exec cat $stdout | grep "ready to accept" | wc -l] > 0} { + if {[exec grep "ready to accept" | wc -l < $stdout] > 0} { break } after 10 diff --git a/tests/support/test.tcl b/tests/support/test.tcl index f66e54b87..480c674e0 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 [list 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)]} diff --git a/tests/support/util.tcl b/tests/support/util.tcl index a39a2134b..675d57f78 100644 --- a/tests/support/util.tcl +++ b/tests/support/util.tcl @@ -294,3 +294,7 @@ proc csvdump r { proc csvstring s { return "\"$s\"" } + +proc roundFloat f { + format "%.10g" $f +} |