Skip to content

Commit

Permalink
[Feat] Support fast fail option for tcl test cases (valkey-io#482)
Browse files Browse the repository at this point in the history
This PR added a new option for tcl test case which will fail fast once any test cases fail.
This can be useful while running redis CI pipeline, and you want to accelerate the CI pipeline.

usage for example

> ./runtest --single unit/type/hash --fast-fail

---------

Signed-off-by: arthur.lee <arthur-lee@qq.com>
  • Loading branch information
arthurkiller authored and srgsanky committed May 19, 2024
1 parent 50d666d commit 209a4aa
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/instances.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ set ::leaked_fds_file [file normalize "tmp/leaked_fds.txt"]
set ::pids {} ; # We kill everything at exit
set ::dirs {} ; # We remove all the temp dirs at exit
set ::run_matching {} ; # If non empty, only tests matching pattern are run.
set ::exit_on_failure 0
set ::stop_on_failure 0
set ::loop 0

Expand Down Expand Up @@ -298,6 +299,8 @@ proc parse_options {} {
set val2 [lindex $::argv [expr $j+2]]
dict set ::global_config $val $val2
incr j 2
} elseif {$opt eq {--fast-fail}} {
set ::exit_on_failure 1
} elseif {$opt eq {--stop}} {
set ::stop_on_failure 1
} elseif {$opt eq {--loop}} {
Expand All @@ -316,6 +319,7 @@ proc parse_options {} {
puts "--tls-module Run tests in TLS mode with Valkey module."
puts "--host <host> Use hostname instead of 127.0.0.1."
puts "--config <k> <v> Extra config argument(s)."
puts "--fast-fail Exit immediately once the first test fails."
puts "--stop Blocks once the first test fails."
puts "--loop Execute the specified set of tests forever."
puts "--help Shows this help."
Expand Down Expand Up @@ -483,6 +487,11 @@ while 1 {
incr ::failed
# letting the tests resume, so we'll eventually reach the cleanup and report crashes

if {$::exit_on_failure} {
puts -nonewline "(Fast fail: test will exit now)"
flush stdout
exit 1
}
if {$::stop_on_failure} {
puts -nonewline "(Test stopped, press enter to resume the tests)"
flush stdout
Expand Down
5 changes: 5 additions & 0 deletions tests/support/test.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,11 @@ proc test {name code {okpattern undefined} {tags {}}} {
incr ::num_failed
send_data_packet $::test_server_fd err [join $details "\n"]

if {$::exit_on_failure} {
puts "Test error (last server port:[srv port], log:[srv stdout]), test will exit now"
flush stdout
exit 1
}
if {$::stop_on_failure} {
puts "Test error (last server port:[srv port], log:[srv stdout]), press enter to teardown the test."
flush stdout
Expand Down
9 changes: 9 additions & 0 deletions tests/test_helper.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ set ::active_servers {} ; # Pids of active server instances.
set ::dont_clean 0
set ::dont_pre_clean 0
set ::wait_server 0
set ::exit_on_failure 0
set ::stop_on_failure 0
set ::dump_logs 0
set ::loop 0
Expand Down Expand Up @@ -383,6 +384,11 @@ proc read_from_test_client fd {
puts $err
lappend ::failed_tests $err
set ::active_clients_task($fd) "(ERR) $data"
if {$::exit_on_failure} {
puts -nonewline "(Fast fail: test will exit now)"
flush stdout
exit 1
}
if {$::stop_on_failure} {
puts -nonewline "(Test stopped, press enter to resume the tests)"
flush stdout
Expand Down Expand Up @@ -564,6 +570,7 @@ proc print_help_screen {} {
"--dont-clean Don't delete valkey log files after the run."
"--dont-pre-clean Don't delete existing valkey log files before the run."
"--no-latency Skip latency measurements and validation by some tests."
"--fastfail Exit immediately once the first test fails."
"--stop Blocks once the first test fails."
"--loop Execute the specified set of tests forever."
"--loops <count> Execute the specified set of tests several times."
Expand Down Expand Up @@ -688,6 +695,8 @@ for {set j 0} {$j < [llength $argv]} {incr j} {
set ::wait_server 1
} elseif {$opt eq {--dump-logs}} {
set ::dump_logs 1
} elseif {$opt eq {--fastfail}} {
set ::exit_on_failure 1
} elseif {$opt eq {--stop}} {
set ::stop_on_failure 1
} elseif {$opt eq {--loop}} {
Expand Down

0 comments on commit 209a4aa

Please sign in to comment.