warpgate/tests/06-writeback/test-shutdown-drain.sh
grabbit a2d49137f9 Add comprehensive test suite: 63 integration tests + 110 Rust unit tests
Integration tests (tests/):
- 9 categories covering config, lifecycle, signals, supervision,
  cache, writeback, network faults, crash recovery, and CLI
- Shell-based harness with mock NAS (network namespace + SFTP),
  fault injection (tc netem), and power loss simulation
- TAP format runner (run-all.sh) with proper SKIP detection

Rust unit tests (warpgate/src/):
- 110 tests across 14 modules, all passing in 0.01s
- Config parsing, defaults validation, RestartTracker logic,
  RC API response parsing, rclone arg generation, service
  config generation, CLI output formatting, warmup path logic

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 11:21:35 +08:00

50 lines
1.3 KiB
Bash
Executable File

#!/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)"