Skip to content

Commit 80f5a0d

Browse files
committed
Clean up testsuite children before entire testsuite
1 parent a4ad1d7 commit 80f5a0d

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

tests/testrunner.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ function testrunner::absolute_path() {
5555
printf "$(cd "$(dirname "$1")" && pwd)/$(basename "$1")"
5656
}
5757

58+
function testrunner::pid() {
59+
# Portable subshell-aware PID
60+
exec bash -c 'echo $PPID'
61+
}
62+
5863
declare test_output_dir=$(mktemp -d)
5964

6065
function testrunner::run_test() {
@@ -162,6 +167,10 @@ function testrunner::run_tests() {
162167
testrunner::run_test teardown
163168
fi
164169

170+
# Clean up if test didn't do it
171+
testrunner::signal_children TERM
172+
testrunner::signal_children KILL
173+
165174
if [[ -z "$test_failure" ]]; then
166175
printf "\n" # Blank line in case the last test passed
167176
fi
@@ -236,7 +245,8 @@ function testrunner::print_test_output {
236245
function testrunner::signal_children()
237246
{
238247
local signal=${1:-TERM}
239-
local pid=${2:-${BASHPID:-$$}}
248+
local subshell_pid=$(testrunner::pid)
249+
local pid=${2:-${BASHPID:-${subshell_pid:-$$}}}
240250

241251
local child_pids=()
242252

@@ -316,7 +326,6 @@ for testsuite in "${testsuites[@]}"; do
316326
# Export results out of sub-shell
317327
printf "tests_total+=${tests_total}; tests_failed+=${tests_failed}" >&3
318328
319-
# Clean up if test didn't do it
320329
testrunner::signal_children TERM $$
321330
testrunner::signal_children KILL $$
322331
)

0 commit comments

Comments
 (0)