#!/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 start_mock_nas # Generate config with a long write-back delay so files stay dirty gen_config write_back=30s # Start warpgate and wait for mount + RC API start_warpgate wait_for_mount wait_for_rc_api # Write a file through the FUSE mount — it will be cached locally # but not yet written back to the NAS due to the 30s write-back delay echo "dirty-data" > "$TEST_MOUNT/dirty-test.txt" # Allow a moment for VFS to register the dirty file sleep 2 # Verify the file is counted as 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 — the shutdown should drain the write-back queue # before unmounting and exiting kill -TERM "$WARPGATE_PID" # Wait for exit — drain may take a moment wait_for_exit "$WARPGATE_PID" 60 # Verify the shutdown drained the write-back queue assert_log_contains "Signal received, shutting down" assert_log_contains "Waiting for write-back queue" assert_log_contains "Write-back queue drained" # Verify the dirty file was flushed to the NAS before exit assert_file_exists "$NAS_ROOT/dirty-test.txt" # Verify the content matches what we wrote actual=$(cat "$NAS_ROOT/dirty-test.txt") if [[ "$actual" != "dirty-data" ]]; then echo "FAIL: NAS file content mismatch: expected 'dirty-data', got '$actual'" >&2 exit 1 fi # Verify the FUSE mount was removed assert_not_mounted echo "PASS: $(basename "$0" .sh)"