warpgate/tests/03-signal/test-sigkill-orphans.sh
grabbit a2d49137f9 Add comprehensive test suite: 63 integration tests + 110 Rust unit tests
Integration tests (tests/):
- 9 categories covering config, lifecycle, signals, supervision,
  cache, writeback, network faults, crash recovery, and CLI
- Shell-based harness with mock NAS (network namespace + SFTP),
  fault injection (tc netem), and power loss simulation
- TAP format runner (run-all.sh) with proper SKIP detection

Rust unit tests (warpgate/src/):
- 110 tests across 14 modules, all passing in 0.01s
- Config parsing, defaults validation, RestartTracker logic,
  RC API response parsing, rclone arg generation, service
  config generation, CLI output formatting, warmup path logic

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 11:21:35 +08:00

73 lines
2.1 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
source "$SCRIPT_DIR/../harness/helpers.sh"
source "$SCRIPT_DIR/../harness/mock-nas.sh"
require_root
setup_test_env
trap teardown_test_env EXIT
# Start the mock NAS
start_mock_nas
# Generate a default config
gen_config
# Start warpgate and wait for full startup
start_warpgate
wait_for_log_line "Supervision active" 60
# Record the PID before killing
local_pid="$WARPGATE_PID"
# Send SIGKILL — this bypasses all signal handlers.
# The supervisor cannot perform orderly shutdown.
# rclone and smbd were spawned with .process_group(0), so they are
# in separate process groups and will NOT receive the SIGKILL.
kill -KILL "$local_pid"
# Wait for the killed process to be reaped
sleep 2
# Clear WARPGATE_PID so teardown does not try to SIGTERM a dead process
WARPGATE_PID=""
# Check for orphan rclone processes — since SIGKILL prevents cleanup,
# orphans are expected. This test documents the behavior.
orphan_rclone=$(pgrep -c -f "rclone.*$TEST_MOUNT" 2>/dev/null || echo 0)
orphan_smbd=$(pgrep -c -f "smbd.*$TEST_DIR" 2>/dev/null || echo 0)
if [[ "$orphan_rclone" -gt 0 ]]; then
echo "INFO: found $orphan_rclone orphan rclone process(es) after SIGKILL (expected — process group isolation)"
fi
if [[ "$orphan_smbd" -gt 0 ]]; then
echo "INFO: found $orphan_smbd orphan smbd process(es) after SIGKILL (expected — process group isolation)"
fi
# Clean up any orphan processes manually (don't rely on teardown alone)
pkill -9 -f "rclone.*$TEST_MOUNT" 2>/dev/null || true
pkill -9 -f "smbd.*$TEST_DIR" 2>/dev/null || true
sleep 1
# Unmount stale FUSE mount
if mountpoint -q "$TEST_MOUNT" 2>/dev/null; then
fusermount3 -uz "$TEST_MOUNT" 2>/dev/null || fusermount -uz "$TEST_MOUNT" 2>/dev/null || true
sleep 1
fi
# Assert no orphan rclone/smbd processes remain after cleanup
assert_no_orphan_rclone
orphan_smbd_after=$(pgrep -c -f "smbd.*$TEST_DIR" 2>/dev/null || echo 0)
if [[ "$orphan_smbd_after" -gt 0 ]]; then
echo "FAIL: orphan smbd processes still remain after cleanup" >&2
exit 1
fi
# Assert mount is unmounted
assert_not_mounted
echo "PASS: $(basename "$0" .sh)"