From 4d74505087b3adc81f9580d8eeb46961c00b6565 Mon Sep 17 00:00:00 2001 From: Felipe Lalanne <1822826+pipex@users.noreply.github.com> Date: Fri, 27 Jan 2023 18:01:03 -0300 Subject: [PATCH] Fix wait-for-it script to work with external signals The wait-for-it script used during tests would setup a timer that would send SIGUSR2 to the parent process after the timer ends. Since node was ignoring additional signals, the timer ending would have no effect after the node process had replaced the start script. However when node has pid != 1, SIGUSR2 default behavior is to terminate the process, meaning the tests would fail after 30 seconds. The script is now updated so the timer is killed once the services are ready for the tests. --- test/lib/wait-for-it.sh | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/test/lib/wait-for-it.sh b/test/lib/wait-for-it.sh index 6ac9c816..74f79f08 100755 --- a/test/lib/wait-for-it.sh +++ b/test/lib/wait-for-it.sh @@ -72,21 +72,18 @@ set_abort_timer() { kill -USR2 "$2" } -# Flag indicating whether the required services are ready -ready=0 abort_if_not_ready() { # If the timeout is reached and the required services are not ready, it probably # means something went wrong so we terminate the program with an error - if [ "${ready}" = "0" ]; then - echo "Something happened, failed to start in ${timeout}s" >&2 - exit 1 - fi + echo "Something happened, failed to start in ${timeout}s" >&2 + exit 1 } # Trap the signal and start the timer if user timeout is greater than 0 if [ "$timeout" -gt 0 ]; then trap 'abort_if_not_ready' USR2 set_abort_timer "$timeout" $$ & + timer_pid=$! fi # Wait for docker @@ -110,7 +107,9 @@ if [ "${with_supervisor}" = "1" ]; then done fi -# Ignore signal if received -ready=1 +# Kill the timer since we are ready to start +if [ "$timer_pid" != "" ]; then + kill $timer_pid +fi exec ${cmd}