#!/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" # Test: drain returns immediately when the RC API is unavailable. # Specifically tests the drain path: write a dirty file with long write-back, # kill rclone (removing the RC API), then send SIGTERM. The drain function # should detect the RC API is gone and return immediately without hanging. require_root setup_test_env trap teardown_test_env EXIT start_mock_nas # Use a very long write-back delay so the file stays dirty gen_config write_back=300s start_warpgate wait_for_mount wait_for_rc_api # Write a dirty file through the mount — it will stay dirty due to 300s delay dd if=/dev/urandom bs=1K count=64 2>/dev/null | \ dd of="$TEST_MOUNT/drain-test.dat" bs=1K 2>/dev/null # Allow VFS to register the dirty write sleep 2 # Kill rclone directly — simulates an unexpected crash, removing the RC API pkill -f "rclone mount.*$TEST_MOUNT" # Brief pause for the supervisor to detect rclone exit sleep 1 # Send SIGTERM to trigger graceful shutdown with drain. # The drain function should detect that the RC API is gone and return # immediately rather than hanging for the drain timeout. if kill -0 "$WARPGATE_PID" 2>/dev/null; then kill -TERM "$WARPGATE_PID" fi # Warpgate should exit quickly since drain cannot poll vfs/stats wait_for_exit "$WARPGATE_PID" 30 # Verify warpgate noticed the unexpected rclone exit assert_log_contains "rclone mount exited unexpectedly" echo "PASS: $(basename "$0" .sh)"