#!/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: graceful shutdown drains the write-back queue before exiting. # A file written through the FUSE mount with a long write-back delay should # still arrive on the NAS after SIGTERM triggers the drain procedure. require_root setup_test_env trap teardown_test_env EXIT start_mock_nas # Long write-back delay ensures the file stays dirty until drain gen_config write_back=30s start_warpgate wait_for_mount wait_for_rc_api # Write a file through the FUSE mount echo "drain-test-data" > "$TEST_MOUNT/drain.txt" # Allow VFS to register the write sleep 1 # Verify the file is dirty (not yet written back) dirty=$(get_dirty_count) if [[ "$dirty" -lt 1 ]]; then echo "FAIL: expected dirty count > 0, got $dirty" >&2 exit 1 fi # Send SIGTERM to trigger orderly shutdown with write-back drain kill -TERM "$WARPGATE_PID" # Wait for exit — drain must flush the file before unmounting wait_for_exit "$WARPGATE_PID" 60 # Verify the drain procedure was logged assert_log_contains "Waiting for write-back queue" # Verify the file arrived on the NAS with correct content assert_file_content "$NAS_ROOT/drain.txt" "drain-test-data" echo "PASS: $(basename "$0" .sh)"