#!/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 # Send SIGTERM twice in quick succession — the second signal should # not cause a crash or panic. The shutdown flag is set on first signal; # the second should be idempotent. kill -TERM "$WARPGATE_PID" sleep 0.5 kill -TERM "$WARPGATE_PID" 2>/dev/null || true # Wait for the process to exit wait_for_exit "$WARPGATE_PID" 30 # Verify exit code 0 (no crash from double signal) wait "$WARPGATE_PID" 2>/dev/null code=$? if [[ "$code" -ne 0 ]]; then echo "FAIL: expected exit code 0, got $code" >&2 exit 1 fi # Verify orderly shutdown occurred assert_log_contains "Signal received, shutting down" # Verify the FUSE mount was removed assert_not_mounted # Verify no orphan rclone processes remain assert_no_orphan_rclone echo "PASS: $(basename "$0" .sh)"