Skip to content

Commit a350004

Browse files
committed
test(watchdog): guard the ps -W pipeline for POSIX cleanup
CI caught the macOS run exiting 1 AFTER the watchdog assertion passed ('ok: child exited after parent death' followed by exit code 1): the kill_hard helper resolved the Windows pid with 'ps -W', an MSYS-only flag. Under 'set -euo pipefail' the failing ps aborts the helper, the '[[ -n ]] && kill_hard' statement inherits that status, and the EXIT trap turns a passing test into a red job. Linux ps would fail the same way. Guard the pipeline (empty winpid on POSIX, where the flag does not exist) and restore the bare '|| true' tail on every cleanup kill, which the original script had and my refactor dropped. Signed-off-by: 周文瑄 <zhouwx1997@126.com>
1 parent 92725a5 commit a350004

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

‎tests/test_parent_watchdog.sh‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@ kill_hard() {
4040
# so a child's real parent never actually died). Force-kill through
4141
# TerminateProcess on the Windows pid as well. The winpid must be resolved
4242
# BEFORE the msys kill: kill -9 removes the pid from the MSYS process table
43-
# immediately, and the mapping would be lost.
43+
# immediately, and the mapping would be lost. `ps -W` exists only on MSYS —
44+
# under `set -o pipefail` a failing ps would abort this helper on POSIX —
45+
# so the pipeline is guarded and simply yields an empty winpid elsewhere.
4446
local pid="$1" winpid
45-
winpid="$(ps -W 2>/dev/null | awk -v m="${pid}" '$1==m {print $4; exit}')"
47+
winpid="$(ps -W 2>/dev/null | awk -v m="${pid}" '$1==m {print $4; exit}' || true)"
4648
kill -9 "${pid}" 2>/dev/null || true
4749
[[ -n "${winpid}" ]] && taskkill //F //PID "${winpid}" >/dev/null 2>&1 || true
4850
}
@@ -51,14 +53,14 @@ cleanup() {
5153
if [[ -s "${tmpdir}/child.pid" ]]; then
5254
local child_pid
5355
child_pid="$(cat "${tmpdir}/child.pid" 2>/dev/null || true)"
54-
[[ -n "${child_pid}" ]] && kill_hard "${child_pid}"
56+
[[ -n "${child_pid}" ]] && kill_hard "${child_pid}" || true
5557
fi
5658
# On Windows the pipe writer is an orphaned helper that outlives the wrapper
5759
# by design (it holds stdin open); only the test knows its PID.
5860
if [[ -n "${writer_pid}" ]]; then
59-
kill_hard "${writer_pid}"
61+
kill_hard "${writer_pid}" || true
6062
fi
61-
[[ -n "${wrapper_pid}" ]] && kill_hard "${wrapper_pid}"
63+
[[ -n "${wrapper_pid}" ]] && kill_hard "${wrapper_pid}" || true
6264
cbm_test_runtime_cleanup "${BINARY}"
6365
}
6466
trap cleanup EXIT

0 commit comments

Comments
 (0)