From 80f5a0dda4dfdfaa8fa3df9b80ed53e304b0203a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Wed, 30 Jun 2021 20:40:23 +0200 Subject: [PATCH] Clean up testsuite children before entire testsuite --- tests/testrunner.sh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tests/testrunner.sh b/tests/testrunner.sh index 29c75c9..92dcf4d 100755 --- a/tests/testrunner.sh +++ b/tests/testrunner.sh @@ -55,6 +55,11 @@ function testrunner::absolute_path() { printf "$(cd "$(dirname "$1")" && pwd)/$(basename "$1")" } +function testrunner::pid() { + # Portable subshell-aware PID + exec bash -c 'echo $PPID' +} + declare test_output_dir=$(mktemp -d) function testrunner::run_test() { @@ -162,6 +167,10 @@ function testrunner::run_tests() { testrunner::run_test teardown fi + # Clean up if test didn't do it + testrunner::signal_children TERM + testrunner::signal_children KILL + if [[ -z "$test_failure" ]]; then printf "\n" # Blank line in case the last test passed fi @@ -236,7 +245,8 @@ function testrunner::print_test_output { function testrunner::signal_children() { local signal=${1:-TERM} - local pid=${2:-${BASHPID:-$$}} + local subshell_pid=$(testrunner::pid) + local pid=${2:-${BASHPID:-${subshell_pid:-$$}}} local child_pids=() @@ -316,7 +326,6 @@ for testsuite in "${testsuites[@]}"; do # Export results out of sub-shell printf "tests_total+=${tests_total}; tests_failed+=${tests_failed}" >&3 - # Clean up if test didn't do it testrunner::signal_children TERM $$ testrunner::signal_children KILL $$ )