warpgate/tests/06-writeback/test-drain-timeout.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

44 lines
1.1 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: write-back drain times out when transfers cannot complete.
# Extreme network latency prevents the drain from finishing within the
# 300s timeout, so warpgate should log a timeout and exit anyway.
# This is a slow test (>300s) — requires WARPGATE_TEST_LONG=1.
require_root
require_long_tests
setup_test_env
trap teardown_test_env EXIT
start_mock_nas
gen_config write_back=5s
start_warpgate
wait_for_mount
wait_for_rc_api
# Write a file so there is something to drain
echo "timeout-test-data" > "$TEST_MOUNT/timeout.txt"
# Allow VFS to register the write
sleep 1
# Inject extreme latency — 10s per packet makes transfer effectively impossible
inject_latency 10000
# Send SIGTERM to initiate shutdown + drain
kill -TERM "$WARPGATE_PID"
# The drain timeout is 300s; allow additional margin for shutdown
wait_for_exit "$WARPGATE_PID" 320
# Verify the drain timed out
assert_log_contains "write-back drain timed out"
echo "PASS: $(basename "$0" .sh)"