warpgate/tests/06-writeback/test-offline-write-restore.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

53 lines
1.2 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: files written while the network is down are uploaded once restored.
# Dirty files accumulate during the outage and drain automatically when
# connectivity returns.
require_root
setup_test_env
trap teardown_test_env EXIT
start_mock_nas
gen_config write_back=2s
start_warpgate
wait_for_mount
wait_for_rc_api
# Sever the network — uploads will fail
inject_network_down
# Write 5 files through the mount while offline
for i in $(seq 1 5); do
echo "offline-data-$i" > "$TEST_MOUNT/offline-$i.txt"
done
# Allow VFS to register all writes
sleep 2
# All 5 files should be dirty (cannot upload)
dirty=$(get_dirty_count)
if [[ "$dirty" -lt 5 ]]; then
echo "FAIL: expected dirty count >= 5, got $dirty" >&2
exit 1
fi
# Restore the network — rclone should resume uploads
inject_network_up
# Wait for all dirty files to drain
wait_for_dirty_zero 120
# Verify all 5 files arrived on the NAS with correct content
for i in $(seq 1 5); do
assert_file_content "$NAS_ROOT/offline-$i.txt" "offline-data-$i"
done
echo "PASS: $(basename "$0" .sh)"