#!/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 mock NAS and bring warpgate to full supervision start_mock_nas gen_config start_warpgate wait_for_log_line "Supervision active" 60 # Initiate graceful shutdown stop_warpgate # Verify shutdown messages appear in the correct order assert_log_contains "Shutting down" assert_log_order "SMB: stopped" "FUSE: unmounted" assert_log_order "FUSE: unmounted" "rclone: stopped" # Verify the drain step appears between SMB stop and FUSE unmount # The supervisor should drain dirty writes before tearing down the FUSE mount. if grep -q "Write-back queue drained\|Waiting for write-back" "$TEST_DIR/warpgate.log" 2>/dev/null; then assert_log_order "SMB: stopped" "Write-back queue drained\|Waiting for write-back" # Verify drain completes before FUSE unmount drain_line=$(grep -n "Write-back queue drained\|Waiting for write-back" "$TEST_DIR/warpgate.log" | head -1 | cut -d: -f1) fuse_line=$(grep -n "FUSE: unmounted" "$TEST_DIR/warpgate.log" | head -1 | cut -d: -f1) if [[ -n "$drain_line" && -n "$fuse_line" && "$drain_line" -ge "$fuse_line" ]]; then echo "FAIL: drain step should appear before FUSE unmount" >&2 exit 1 fi fi echo "PASS: $(basename "$0" .sh)"