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