Skip to content

Commit

Permalink
Fail tests immediately if the server is no longer running (#678)
Browse files Browse the repository at this point in the history
Fix a minor inconvenience I have when writing tests. If I have a typo or
forget to generate the tls certificates, the start_server handle will
just loop for 2 minutes before printing the error. This just fails and
prints as soon as it sees the error.

Signed-off-by: Madelyn Olson <[email protected]>
  • Loading branch information
madolson authored Jun 21, 2024
1 parent bf1fb1f commit ce79539
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions tests/support/server.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ proc spawn_server {config_file stdout stderr args} {
}

# Wait for actual startup, return 1 if port is busy, 0 otherwise
proc wait_server_started {config_file stdout pid} {
proc wait_server_started {config_file stdout stderr pid} {
set checkperiod 100; # Milliseconds
set maxiter [expr {120*1000/$checkperiod}] ; # Wait up to 2 minutes.
set port_busy 0
Expand All @@ -328,6 +328,13 @@ proc wait_server_started {config_file stdout pid} {
set port_busy 1
break
}

# Configuration errors are unexpected, but it's helpful to fail fast
# to give the feedback to the test runner.
if {[regexp {FATAL CONFIG FILE ERROR} [exec cat $stderr]]} {
start_server_error $config_file "Configuration issue prevented Valkey startup"
break
}
}
return $port_busy
}
Expand Down Expand Up @@ -568,7 +575,7 @@ proc start_server {options {code undefined}} {
set pid [spawn_server $config_file $stdout $stderr $args]

# check that the server actually started
set port_busy [wait_server_started $config_file $stdout $pid]
set port_busy [wait_server_started $config_file $stdout $stderr $pid]

# Sometimes we have to try a different port, even if we checked
# for availability. Other test clients may grab the port before we
Expand Down Expand Up @@ -778,7 +785,7 @@ proc restart_server {level wait_ready rotate_logs {reconnect 1} {shutdown sigter
set pid [spawn_server $config_file $stdout $stderr {}]

# check that the server actually started
wait_server_started $config_file $stdout $pid
wait_server_started $config_file $stdout $stderr $pid

# update the pid in the servers list
dict set srv "pid" $pid
Expand Down

0 comments on commit ce79539

Please sign in to comment.