Test framework: exit on timeout with report.

There was no sane way to detect tests that may never end because of
Redis bugs or tests bugs.
This commit is contained in:
antirez 2014-11-28 11:05:58 +01:00
parent 669aa2a210
commit 8acb3a8843

View File

@ -65,6 +65,8 @@ set ::file ""; # If set, runs only the tests in this comma separated list
set ::curfile ""; # Hold the filename of the current suite set ::curfile ""; # Hold the filename of the current suite
set ::accurate 0; # If true runs fuzz tests with more iterations set ::accurate 0; # If true runs fuzz tests with more iterations
set ::force_failure 0 set ::force_failure 0
set ::timeout 600; # 10 minutes without progresses will quit the test.
set ::last_progress [clock seconds]
# Set to 1 when we are running in client mode. The Redis test uses a # Set to 1 when we are running in client mode. The Redis test uses a
# server-client model to run tests simultaneously. The server instance # server-client model to run tests simultaneously. The server instance
@ -200,11 +202,18 @@ proc test_server_main {} {
vwait forever vwait forever
} }
# This function gets called 10 times per second, for now does nothing but # This function gets called 10 times per second.
# may be used in the future in order to detect test clients taking too much
# time to execute the task.
proc test_server_cron {} { proc test_server_cron {} {
# Do some work here. set elapsed [expr {[clock seconds]-$::last_progress}]
if {$elapsed > $::timeout} {
set err "\[[colorstr red TIMEOUT]\]: clients state report follows."
puts $err
show_clients_state
kill_clients
the_end
}
after 100 test_server_cron after 100 test_server_cron
} }
@ -230,6 +239,8 @@ proc read_from_test_client fd {
set bytes [gets $fd] set bytes [gets $fd]
set payload [read $fd $bytes] set payload [read $fd $bytes]
foreach {status data} $payload break foreach {status data} $payload break
set ::last_progress [clock seconds]
if {$status eq {ready}} { if {$status eq {ready}} {
if {!$::quiet} { if {!$::quiet} {
puts "\[$status\]: $data" puts "\[$status\]: $data"
@ -256,9 +267,7 @@ proc read_from_test_client fd {
set ::active_clients_task($fd) "(ERR) $data" set ::active_clients_task($fd) "(ERR) $data"
} elseif {$status eq {exception}} { } elseif {$status eq {exception}} {
puts "\[[colorstr red $status]\]: $data" puts "\[[colorstr red $status]\]: $data"
foreach p $::clients_pids { kill_clients
catch {exec kill -9 $p}
}
exit 1 exit 1
} elseif {$status eq {testing}} { } elseif {$status eq {testing}} {
set ::active_clients_task($fd) "(IN PROGRESS) $data" set ::active_clients_task($fd) "(IN PROGRESS) $data"
@ -269,14 +278,7 @@ proc read_from_test_client fd {
} }
} }
# A new client is idle. Remove it from the list of active clients and proc show_clients_state {} {
# if there are still test units to run, launch them.
proc signal_idle_client fd {
# Remove this fd from the list of active clients.
set ::active_clients \
[lsearch -all -inline -not -exact $::active_clients $fd]
if 0 {
# The following loop is only useful for debugging tests that may # The following loop is only useful for debugging tests that may
# enter an infinite loop. Commented out normally. # enter an infinite loop. Commented out normally.
foreach x $::active_clients { foreach x $::active_clients {
@ -286,7 +288,22 @@ proc signal_idle_client fd {
puts "$x => ???" puts "$x => ???"
} }
} }
}
proc kill_clients {} {
foreach p $::clients_pids {
catch {exec kill $p}
} }
}
# A new client is idle. Remove it from the list of active clients and
# if there are still test units to run, launch them.
proc signal_idle_client fd {
# Remove this fd from the list of active clients.
set ::active_clients \
[lsearch -all -inline -not -exact $::active_clients $fd]
if 0 {show_clients_state}
# New unit to process? # New unit to process?
if {$::next_test != [llength $::all_tests]} { if {$::next_test != [llength $::all_tests]} {