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