warpgate/tests/07-network/test-read-network-cut.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

61 lines
1.7 KiB
Bash
Executable File

#!/usr/bin/env bash
# Test: read I/O fails when network is severed mid-transfer
#
# Creates a 5 MB file on the mock NAS, starts reading it through the FUSE
# mount, then immediately cuts the network. The background read should fail
# with an I/O error or produce incomplete output because the remote is
# unreachable mid-stream.
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
# --- Arrange ---
start_mock_nas
nas_create_file "bigfile.dat" 51200 # 50 MB — large enough that caching
# takes time, ensuring network cut
# hits mid-transfer
gen_config
start_warpgate
wait_for_mount
wait_for_rc_api
# --- Act ---
# Start a background read of the large file
cat "$TEST_MOUNT/bigfile.dat" > /dev/null 2>&1 &
read_pid=$!
_BG_PIDS+=("$read_pid")
# Brief delay to let the read begin but NOT complete for a 50 MB file
sleep 0.5
# Sever the network link while the read is in progress
inject_network_down
# Wait for the background read to finish (it should error out)
read_ok=0
if wait "$read_pid" 2>/dev/null; then
read_ok=1
fi
# --- Assert ---
# With a 50 MB file and the network cut after 0.5s, the read must fail.
# The file cannot have been fully cached in that time.
if [[ "$read_ok" -eq 1 ]]; then
echo "FAIL: background read of 50 MB file succeeded despite network cut" >&2
echo " The file should not have been fully cached in 0.5s." >&2
inject_network_up
exit 1
fi
# Restore network for clean teardown
inject_network_up
echo "PASS: $(basename "$0" .sh)"