diff --git a/test/shell.d/base-test.sh b/test/shell.d/base-test.sh index 838628221930..b565ea873627 100644 --- a/test/shell.d/base-test.sh +++ b/test/shell.d/base-test.sh @@ -59,6 +59,23 @@ shell_ipc_socket() { printf '%s/omarchy-shell-%s.sock\n' "${XDG_RUNTIME_DIR:-/run/user/$UID}" "${id:0:16}" } +# A fixture can leave children behind after Quickshell exits; its setsid group +# still reaches them, including children that need KILL after a TERM grace period. +stop_process_group() { + local pid="$1" attempt + + kill -TERM -- "-$pid" 2>/dev/null || true + for attempt in {1..20}; do + if ! pgrep -g "$pid" >/dev/null 2>&1; then + wait "$pid" 2>/dev/null || true + return 0 + fi + sleep 0.1 + done + kill -KILL -- "-$pid" 2>/dev/null || true + wait "$pid" 2>/dev/null || true +} + require_command() { local command="$1" @@ -130,25 +147,9 @@ QML_FIXTURE_TMP="" QML_FIXTURE_PID="" QML_FIXTURE_LOG="" -# The fixture's Quickshell and every process it started, deepest last. -qml_fixture_tree() { - local pid=$1 child - printf '%s\n' "$pid" - for child in $(pgrep -P "$pid" 2>/dev/null); do - qml_fixture_tree "$child" - done -} - qml_fixture_cleanup() { - local -a tree=() local attempt - if [[ -n $QML_FIXTURE_PID ]] && kill -0 "$QML_FIXTURE_PID" 2>/dev/null; then - # Processes a fixture started outlive Quickshell and can still be writing - # into its HOME while that is removed, so stop them with it. - mapfile -t tree < <(qml_fixture_tree "$QML_FIXTURE_PID") - kill "${tree[@]}" 2>/dev/null || true - wait "$QML_FIXTURE_PID" 2>/dev/null || true - fi + [[ -n $QML_FIXTURE_PID ]] && stop_process_group "$QML_FIXTURE_PID" QML_FIXTURE_PID="" if [[ -n $QML_FIXTURE_TMP && -d $QML_FIXTURE_TMP ]]; then # A child that was mid-write when it got the signal can still add a file. @@ -185,10 +186,7 @@ run_qml_fixture() { qml_fixture_scratch # A second fixture in the same file must not read the first one's result. - if [[ -n $QML_FIXTURE_PID ]] && kill -0 "$QML_FIXTURE_PID" 2>/dev/null; then - kill "$QML_FIXTURE_PID" 2>/dev/null || true - wait "$QML_FIXTURE_PID" 2>/dev/null || true - fi + [[ -n $QML_FIXTURE_PID ]] && stop_process_group "$QML_FIXTURE_PID" config_dir="$QML_FIXTURE_TMP/$fixture" result="$QML_FIXTURE_TMP/result.json" QML_FIXTURE_LOG="$QML_FIXTURE_TMP/quickshell.log" @@ -208,7 +206,7 @@ run_qml_fixture() { QML2_IMPORT_PATH="$ROOT/shell${QML2_IMPORT_PATH:+:$QML2_IMPORT_PATH}" \ QML_IMPORT_PATH="$ROOT/shell${QML_IMPORT_PATH:+:$QML_IMPORT_PATH}" \ PATH="$QML_FIXTURE_TMP/bin:$ROOT/bin:$PATH" \ - quickshell -p "$config_dir" --no-color >"$QML_FIXTURE_LOG" 2>&1 & + setsid quickshell -p "$config_dir" --no-color >"$QML_FIXTURE_LOG" 2>&1 & QML_FIXTURE_PID=$! for _ in {1..150}; do diff --git a/test/shell.d/plugin-registry-contract-test.sh b/test/shell.d/plugin-registry-contract-test.sh index 2f84ebab4286..a67116c91f33 100755 --- a/test/shell.d/plugin-registry-contract-test.sh +++ b/test/shell.d/plugin-registry-contract-test.sh @@ -7,3 +7,24 @@ source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh" require_quickshell "plugin registry contract test" run_qml_fixture plugin-registry "plugin registry contract checks pass" services Commons + +watcher="" +for _ in {1..30}; do + watcher=$(pgrep -P "$QML_FIXTURE_PID" -x inotifywait) && break + sleep 0.1 +done +[[ -n $watcher ]] || fail "fixture starts a plugin watcher" +# A stopped child cannot handle TERM, so cleanup must also reach its KILL fallback. +kill -STOP "$watcher" +kill -KILL "$QML_FIXTURE_PID" +wait "$QML_FIXTURE_PID" 2>/dev/null || true +qml_fixture_cleanup +for _ in {1..100}; do + kill -0 "$watcher" 2>/dev/null || break + sleep 0.01 +done +if kill -0 "$watcher" 2>/dev/null; then + kill -KILL "$watcher" 2>/dev/null || true + fail "crashed fixture cleanup stops its surviving plugin watcher" +fi +pass "crashed fixture cleanup stops its surviving plugin watcher" diff --git a/test/shell.d/tray-menu-test.sh b/test/shell.d/tray-menu-test.sh index acf6197a5cf6..5f01ad244578 100644 --- a/test/shell.d/tray-menu-test.sh +++ b/test/shell.d/tray-menu-test.sh @@ -19,9 +19,8 @@ cleanup() { wait "$pid" 2>/dev/null || true fi done - if [[ -n $QS_PID ]] && kill -0 "$QS_PID" 2>/dev/null; then - kill "$QS_PID" 2>/dev/null || true - wait "$QS_PID" 2>/dev/null || true + if [[ -n $QS_PID ]]; then + stop_process_group "$QS_PID" fi [[ -n $TMPDIR && -d $TMPDIR ]] && rm -rf "$TMPDIR" return 0 @@ -62,7 +61,7 @@ HOME="$TMPDIR/home" \ XDG_CONFIG_HOME="$TMPDIR/home/.config" \ XDG_CACHE_HOME="$TMPDIR/home/.cache" \ XDG_STATE_HOME="$TMPDIR/home/.local/state" \ - quickshell -p "$config_dir" --no-color >"$qs_log" 2>&1 & + setsid quickshell -p "$config_dir" --no-color >"$qs_log" 2>&1 & QS_PID=$! OMARCHY_TRAY_MENU_EVENT_RESULT="$event_result" \