#!/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_long_tests 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 smbd once -- this should be restart attempt 1/3 smbd_pid=$(pgrep -f "smbd.*--foreground") if [[ -z "$smbd_pid" ]]; then echo "FAIL: smbd not found" >&2 exit 1 fi kill "$smbd_pid" wait_for_log_line "Restarting smbd in 2s (1/3)" 15 # Wait for the restart to complete sleep 5 # Verify smbd is back if ! pgrep -f "smbd.*--foreground" > /dev/null; then echo "FAIL: smbd did not restart after first kill" >&2 exit 1 fi # Sleep longer than RESTART_STABLE_PERIOD (300s) to reset the counter echo "Waiting 310s for stable period to reset restart counter..." sleep 310 # Kill smbd again -- counter should have reset, so this is 1/3 again smbd_pid=$(pgrep -f "smbd.*--foreground") if [[ -z "$smbd_pid" ]]; then echo "FAIL: smbd not found after stable period" >&2 exit 1 fi kill "$smbd_pid" wait_for_log_line "Restarting smbd in 2s (1/3).*" 15 # Count occurrences of "1/3" -- should appear twice (once per kill) count=$(grep -c "Restarting smbd in 2s (1/3)" "$TEST_DIR/warpgate.log" || echo 0) if [[ "$count" -lt 2 ]]; then echo "FAIL: expected at least 2 occurrences of '1/3' but got $count" >&2 echo " (counter did not reset after stable period)" >&2 exit 1 fi # Verify there is no "2/3" message (which would mean the counter was NOT reset) if grep -q "Restarting smbd in 4s (2/3)" "$TEST_DIR/warpgate.log" 2>/dev/null; then echo "FAIL: log contains '2/3' -- counter did not reset after stable period" >&2 exit 1 fi echo "PASS: $(basename "$0" .sh)"