From 3de5c71f48a6062b710e4eec6d513860e05e5d5c Mon Sep 17 00:00:00 2001 From: Arthur Lee Date: Wed, 15 May 2024 21:55:24 +0800 Subject: [PATCH] [Feat] Support fast fail option for tcl test cases (#482) 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 --- tests/instances.tcl | 9 +++++++++ tests/support/test.tcl | 5 +++++ tests/test_helper.tcl | 9 +++++++++ 3 files changed, 23 insertions(+) diff --git a/tests/instances.tcl b/tests/instances.tcl index 5b90a60093..3b487423f8 100644 --- a/tests/instances.tcl +++ b/tests/instances.tcl @@ -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 @@ -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}} { @@ -316,6 +319,7 @@ proc parse_options {} { puts "--tls-module Run tests in TLS mode with Valkey module." puts "--host Use hostname instead of 127.0.0.1." puts "--config 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." @@ -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 diff --git a/tests/support/test.tcl b/tests/support/test.tcl index 9c959d9de7..bb59ee7972 100644 --- a/tests/support/test.tcl +++ b/tests/support/test.tcl @@ -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 diff --git a/tests/test_helper.tcl b/tests/test_helper.tcl index 57fb2beb13..a8df6c40a6 100644 --- a/tests/test_helper.tcl +++ b/tests/test_helper.tcl @@ -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 @@ -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 @@ -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 Execute the specified set of tests several times." @@ -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}} {