warpgate/tests/07-network/test-packet-loss.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.4 KiB
Bash
Executable File

#!/usr/bin/env bash
# Test: 10 % packet loss does not corrupt transferred data
#
# Injects 10 % packet loss via tc netem, reads a 500 KB file through the
# FUSE mount, and verifies the content matches the original on the NAS.
# rclone's SFTP retries and TCP retransmissions should compensate for the
# loss so the application sees correct data.
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 "data.dat" 500 # 500 KB
# Capture the NAS-side checksum before any network impairment
expected_cksum=$(nas_file_checksum "data.dat")
gen_config
start_warpgate
wait_for_mount
wait_for_rc_api
# --- Act ---
# Inject 10 % packet loss
inject_packet_loss 10
# Read the file through the FUSE mount
cat "$TEST_MOUNT/data.dat" > /dev/null
# --- Assert ---
# Verify the content read through the mount matches the NAS original
actual_cksum=$(md5sum "$TEST_MOUNT/data.dat" | awk '{print $1}')
if [[ "$actual_cksum" != "$expected_cksum" ]]; then
echo "FAIL: checksum mismatch under 10% packet loss" >&2
echo " expected: $expected_cksum" >&2
echo " actual: $actual_cksum" >&2
clear_network_injection
exit 1
fi
# Clean up tc rules
clear_network_injection
echo "PASS: $(basename "$0" .sh)"