#!/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 so rclone can connect via SFTP start_mock_nas # Generate a default config pointing at the mock NAS gen_config # Start warpgate and wait for full startup start_warpgate wait_for_log_line "Supervision active" 60 # --- Kill #1: expect backoff 2s, counter 1/3 --- smbd_pid=$(pgrep -f "smbd.*--foreground") if [[ -z "$smbd_pid" ]]; then echo "FAIL: smbd not found before kill #1" >&2 exit 1 fi kill "$smbd_pid" wait_for_log_line "Restarting smbd in 2s (1/3)" 15 assert_log_contains "Restarting smbd in 2s (1/3)" # Wait for restart to complete (2s backoff + margin) sleep 4 # --- Kill #2: expect backoff 4s, counter 2/3 --- smbd_pid=$(pgrep -f "smbd.*--foreground") if [[ -z "$smbd_pid" ]]; then echo "FAIL: smbd not found before kill #2" >&2 exit 1 fi kill "$smbd_pid" wait_for_log_line "Restarting smbd in 4s (2/3)" 15 assert_log_contains "Restarting smbd in 4s (2/3)" # Wait for restart to complete (4s backoff + margin) sleep 6 # --- Kill #3: expect backoff 6s, counter 3/3 --- smbd_pid=$(pgrep -f "smbd.*--foreground") if [[ -z "$smbd_pid" ]]; then echo "FAIL: smbd not found before kill #3" >&2 exit 1 fi kill "$smbd_pid" wait_for_log_line "Restarting smbd in 6s (3/3)" 15 assert_log_contains "Restarting smbd in 6s (3/3)" echo "PASS: $(basename "$0" .sh)"