Files
OmniSocket/scripts/local_peer_smoke_test.sh
2026-03-16 22:28:05 +08:00

50 lines
1.3 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# 本机 hub/peer smoke 测试:
# - 启动 1 个 omni_hub
# - 启动 2 个 omni_peerbeta 常驻alpha 发一条消息给 beta
# - 校验 beta 日志里确实收到了 alpha 的消息
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
BUILD_DIR="$ROOT_DIR/build"
TMP_DIR="$(mktemp -d /tmp/omnisocket-peer-smoke.XXXXXX)"
PORT=$((30000 + (RANDOM % 20000)))
PIDS=()
cleanup() {
for pid in "${PIDS[@]:-}"; do
kill "$pid" 2>/dev/null || true
wait "$pid" 2>/dev/null || true
done
rm -rf "$TMP_DIR"
}
trap cleanup EXIT
log() {
printf '[peer-smoke] %s\n' "$1"
}
log "building hub/peer binaries"
make -C "$ROOT_DIR" build/omni_hub build/omni_peer >/dev/null
log "starting hub on port $PORT"
"$BUILD_DIR/omni_hub" -P "$PORT" >"$TMP_DIR/hub.log" 2>&1 &
HUB_PID=$!
PIDS+=("$HUB_PID")
sleep 1
log "starting beta peer"
"$BUILD_DIR/omni_peer" -H 127.0.0.1 -P "$PORT" -i beta -w 4 >"$TMP_DIR/beta.log" 2>&1 &
BETA_PID=$!
PIDS+=("$BETA_PID")
sleep 1
log "starting alpha peer and sending command"
"$BUILD_DIR/omni_peer" -H 127.0.0.1 -P "$PORT" -i alpha -b beta -d beta -m "hello-from-alpha" -w 2 >"$TMP_DIR/alpha.log" 2>&1
wait "$BETA_PID"
grep -q "\[peer alpha -> beta\] hello-from-alpha" "$TMP_DIR/beta.log"
log "peer command tunnel passed"