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>
62 lines
1.7 KiB
Bash
Executable File
62 lines
1.7 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"
|
|
|
|
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)"
|