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>
61 lines
1.7 KiB
Bash
Executable File
61 lines
1.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Test: cached file remains readable after network goes down
|
|
#
|
|
# Verifies that once a file has been pulled into the VFS cache, it can
|
|
# be read even when the connection to the remote NAS is severed.
|
|
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 mock NAS and create a 1 MB test file
|
|
start_mock_nas
|
|
nas_create_file "landscape.jpg" 1024
|
|
|
|
# Generate default config
|
|
gen_config
|
|
|
|
# Start warpgate and wait for readiness
|
|
start_warpgate
|
|
wait_for_mount
|
|
wait_for_rc_api
|
|
|
|
# Read the file through the FUSE mount to cache it
|
|
cat "$TEST_MOUNT/landscape.jpg" > /dev/null
|
|
assert_cached "landscape.jpg"
|
|
|
|
# Save a checksum for verification after network goes down
|
|
expected_cksum=$(md5sum "$TEST_MOUNT/landscape.jpg" | awk '{print $1}')
|
|
|
|
# Sever the network link to the mock NAS
|
|
inject_network_down
|
|
|
|
# Read the file again — should succeed from local cache.
|
|
# Time the read and verify it completes quickly (< 2 seconds for 1 MB).
|
|
read_start=$SECONDS
|
|
actual_cksum=$(md5sum "$TEST_MOUNT/landscape.jpg" | awk '{print $1}')
|
|
read_elapsed=$(( SECONDS - read_start ))
|
|
|
|
if [[ "$actual_cksum" != "$expected_cksum" ]]; then
|
|
echo "FAIL: checksum mismatch after network down" >&2
|
|
echo " expected: $expected_cksum" >&2
|
|
echo " actual: $actual_cksum" >&2
|
|
inject_network_up
|
|
exit 1
|
|
fi
|
|
|
|
if [[ "$read_elapsed" -gt 2 ]]; then
|
|
echo "FAIL: offline cache read took ${read_elapsed}s (expected < 2s for 1 MB)" >&2
|
|
inject_network_up
|
|
exit 1
|
|
fi
|
|
|
|
# Restore the network
|
|
inject_network_up
|
|
|
|
echo "PASS: $(basename "$0" .sh)"
|