Files
RustProxy/scripts/start_stream_backends.sh
T
2026-10-13 00:00:06 +02:00

45 lines
1.6 KiB
Bash
Executable File

#!/usr/bin/env bash
# Start two TCP and two UDP mock backends for RustProxy Stream tests.
# Usage: ./start_stream_backends.sh [bind-host]
# Defaults to loopback for safety. Use 0.0.0.0 only on a controlled test network.
set -euo pipefail
DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
HOST="${1:-127.0.0.1}"
PYTHON="${PYTHON:-python3}"
pids=()
for file in test_stream_tcp.py test_stream_udp.py; do
if [[ ! -f "$DIR/$file" ]]; then
echo "Missing $DIR/$file (place the launcher next to the two test scripts)" >&2
exit 1
fi
done
cleanup() {
trap - EXIT INT TERM
if ((${#pids[@]})); then
kill "${pids[@]}" 2>/dev/null || true
wait "${pids[@]}" 2>/dev/null || true
fi
}
trap cleanup EXIT
trap 'exit 130' INT
trap 'exit 143' TERM
"$PYTHON" "$DIR/test_stream_tcp.py" server --host "$HOST" --port 9101 --backend-id tcp-a & pids+=("$!")
"$PYTHON" "$DIR/test_stream_tcp.py" server --host "$HOST" --port 9102 --backend-id tcp-b & pids+=("$!")
"$PYTHON" "$DIR/test_stream_udp.py" server --host "$HOST" --port 9201 --backend-id udp-a & pids+=("$!")
"$PYTHON" "$DIR/test_stream_udp.py" server --host "$HOST" --port 9202 --backend-id udp-b & pids+=("$!")
printf '\nMock backends for RustProxy (bind: %s):\n' "$HOST"
printf 'TCP: %s:9101 (tcp-a), %s:9102 (tcp-b)\n' "$HOST" "$HOST"
printf 'UDP: %s:9201 (udp-a), %s:9202 (udp-b)\n' "$HOST" "$HOST"
printf 'UDP health probe: PING => PONG\n'
printf 'Stop: Ctrl+C\n\n'
# Stop the group if any backend exits unexpectedly (e.g., port conflict).
wait -n "${pids[@]}"
echo 'A backend stopped; stopping all mock backends.' >&2
exit 1