From 57e782f3789365418d3bc6a25cd0ab178edc3b9c Mon Sep 17 00:00:00 2001 From: Laura Lahesoo Date: Thu, 10 Aug 2023 15:34:56 +0200 Subject: [PATCH 1/3] Exit with error from test-wheel.bash if a background task failed. --- test-wheel.bash | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test-wheel.bash b/test-wheel.bash index 03dd98e..d07e25f 100755 --- a/test-wheel.bash +++ b/test-wheel.bash @@ -13,13 +13,34 @@ pip install pytest cleanup=true trap ' + failed_pids=() + for pid in $(jobs -p); do + if kill -0 $pid >/dev/null 2>&1; then + echo "Process $pid is still running." + else + exit_status=$? + if [[ $exit_status -eq 0 ]]; then + echo "Process $pid exited with zero status." + else + echo "Process $pid exited with nonzero status ($exit_status)." + failed_pids+=("$pid") + fi + fi + done + if [[ -n $(jobs -p) ]]; then echo "→ Killing $(jobs -p)" kill $(jobs -p) fi + if [[ "$cleanup" == "true" ]]; then echo "→ Removing $venv"; rm -rf "$venv" fi + + if [[ ${#failed_pids[@]} -gt 0 ]]; then + echo "The following background processes exited with nonzero status: ${failed_pids[@]}" + exit 1 + fi ' EXIT while [[ $# -gt 0 ]]; do From 1831849fb39713e4620d1634dc3cc99e0c52a840 Mon Sep 17 00:00:00 2001 From: Laura Lahesoo Date: Thu, 10 Aug 2023 16:21:04 +0200 Subject: [PATCH 2/3] Improved log messages in test_wheel.bash. --- test-wheel.bash | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/test-wheel.bash b/test-wheel.bash index d07e25f..70635bc 100755 --- a/test-wheel.bash +++ b/test-wheel.bash @@ -16,22 +16,18 @@ trap ' failed_pids=() for pid in $(jobs -p); do if kill -0 $pid >/dev/null 2>&1; then - echo "Process $pid is still running." + # Background process is still running - good. + kill $pid else exit_status=$? if [[ $exit_status -eq 0 ]]; then - echo "Process $pid exited with zero status." + echo "Background task $pid already exited with zero status." else - echo "Process $pid exited with nonzero status ($exit_status)." + echo "Background task $pid exited with nonzero status ($exit_status)." failed_pids+=("$pid") fi fi done - - if [[ -n $(jobs -p) ]]; then - echo "→ Killing $(jobs -p)" - kill $(jobs -p) - fi if [[ "$cleanup" == "true" ]]; then echo "→ Removing $venv"; rm -rf "$venv" @@ -52,14 +48,15 @@ while [[ $# -gt 0 ]]; do shift ;; -b|--background) - echo "→ Launching Background Task $2 ..." + echo "→ Launching background task: $2" $2 & + echo "... started with PID: $!" sleep 5 shift shift ;; -f|--foreground) - echo "→ Starting $2 ..." + echo "→ Starting foreground task: $2" $2 shift shift From 9054023b8efa55eb71f62828c3a2b8fd5aa251b9 Mon Sep 17 00:00:00 2001 From: Joseph Birkner Date: Thu, 10 Aug 2023 17:08:37 +0200 Subject: [PATCH 3/3] Remove exit 0 form test-wheel.bash and enable set -e --- test-wheel.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test-wheel.bash b/test-wheel.bash index 70635bc..cba84a0 100755 --- a/test-wheel.bash +++ b/test-wheel.bash @@ -1,5 +1,7 @@ #!/usr/bin/env bash +set -e + my_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" . "$my_dir/python.bash" @@ -69,5 +71,3 @@ while [[ $# -gt 0 ]]; do ;; esac done - -exit 0