ci: clean up backend test processes on cancel [CI]
ci/woodpecker/push/web-build Pipeline was successful
ci/woodpecker/push/verify Pipeline was successful
ci/woodpecker/push/dev-image Pipeline was successful

This commit is contained in:
justme committed 2026-10-10 06:48:20 -07:00
1 parent bf3481ebae
commit 04f116e092
2 files changed
+90 -20

No files matched your search

+8 -20
View File
@@ -84,31 +84,19 @@ status=0
# Each test module can spawn its own testhost. Run the whole command in a new
# session and time out its process group, so orphaned testhosts cannot keep the
# Woodpecker step and the shared cache lock alive.
if ! command -v setsid >/dev/null 2>&1; then
echo "setsid is required to enforce the backend test timeout" >&2
if ! command -v python3 >/dev/null 2>&1; then
echo "python3 is required to enforce the backend test timeout" >&2
exit 2
fi
run_with_timeout() {
local seconds="$1" marker="$cache/test-timeout.marker" test_pid watcher_pid result=0
local seconds="$1"
shift
rm -f "$marker"
(
cd "$src/backend"
setsid "$@" &
test_pid=$!
setsid bash -c 'sleep "$1"; : > "$2"; kill -TERM -- "-$3" 2>/dev/null || true' _ "$seconds" "$marker" "$test_pid" >/dev/null 2>&1 &
watcher_pid=$!
wait "$test_pid" || result=$?
if [[ -f "$marker" ]]; then
kill -KILL -- "-$test_pid" 2>/dev/null || true
result=124
fi
kill -TERM -- "-$watcher_pid" 2>/dev/null || true
wait "$watcher_pid" 2>/dev/null || true
rm -f "$marker"
return "$result"
)
# A Python supervisor creates the test's session directly and owns its PID.
# This avoids setsid(1) forking away from the PID tracked by the old shell
# watchdog, which could leave testhosts alive (and holding the cache lock)
# after Woodpecker canceled the step.
(cd "$src/backend" && python3 "$root/ci/run-with-timeout.py" "$seconds" "$@")
}
# Ignore exit 8 from other assemblies with no matching tests; both suites have a hard wall-clock cap.