repair ack, refactor e2e tests

This commit is contained in:
kulikov0 committed 2026-09-12 20:36:19 +02:00
1 parent 9e5357eaa8
commit 88a0b5f1b9
42 files changed
+1732 -792

No files matched your search

+10
View File
@@ -0,0 +1,10 @@
# e2e room reuse. Copy to .env and fill with existing conference links.
# Empty room = platform is SKIPPED (harness refuses to create a new call).
# To allow creating fresh rooms per run, set ALLOW_NEW_ROOMS=1.
ROOM_TELEMOST=""
ROOM_WBSTREAM=""
ROOM_DION=""
ROOM_BITRIX=""
ALLOW_NEW_ROOMS=0
+77
View File
@@ -0,0 +1,77 @@
# headless e2e tests
End-to-end tests for the headless creators and joiners.
Each run starts one creator per platform and keeps it running. Joiners then
connect to that creator one at a time, using different parameters. This tests how
the creator adapts when joiner parameters change.
Each test sends a unique string through the joiner's SOCKS5 proxy, over the
tunnel, to a listener on the creator side. The test passes if the string arrives.
No external network is used.
## Platforms and scenarios
Platforms: telemost, wbstream, dion, bitrix. VK is not supported because it has no
headless SOCKS joiner. A platform skips the scenarios it does not support. For
example, dion supports only connect and kick.
| Scenario | Joiner |
|----------|--------|
| connect | Default video tunnel. |
| dc | `--tunnel-mode dc`. |
| kcp | `--reliable` (KCP). |
| dual | `--dual-track`. |
| kick | Two joiners. The first is expected to be kicked. |
## Rooms
Copy `.env.example` to `.env`. Set `ROOM_<PLATFORM>` to an existing conference link
for each platform you want to test.
If a room is empty, the harness skips that platform. It does not create a new
conference. To create new conferences, set `ALLOW_NEW_ROOMS=1`.
## Cookies
Each platform reads `cookies-<platform>.json` from the repository root. Export
these from the desktop creator app. If a cookie file is missing, the harness skips
that platform.
## Run in Docker
The creator and joiner run in separate network namespaces so their WebRTC ICE does
not collide. This requires Docker.
cd headless/tests/stand
./stand.sh build
./stand.sh run
./stand.sh run bitrix dc kick
./stand.sh sh
`build` cross-compiles the Linux binaries and builds the image. `run` runs the
tests; with no arguments it runs every supported platform and scenario. `run`
mounts the cookie files from the repository root, so refreshed tokens are written
back to them. `sh` opens a shell in the container.
## Run on the host
./build-headless.sh
./headless/tests/run.sh
./headless/tests/run.sh bitrix
Run `build-headless.sh` from the repository root first. Same-host WebRTC video can
fail because the creator and joiner share an IP address. Use the Docker method for
the video scenarios.
## Environment variables
| Variable | Description |
|----------|-------------|
| `FAIL_FAST` | Stop at the first failure. Default `1`. Set to `0` to run all tests. |
| `CREATE_TIMEOUT` | Seconds to wait for the creator to start. |
| `CONNECT_TIMEOUT` | Seconds to wait for a joiner's SOCKS port. |
| `PROBE_TIMEOUT` | Seconds to wait for tunnel traffic. |
| `KICK_TIMEOUT` | Seconds to wait for a kick to take effect. |
| `PORT_BASE` | First local port to allocate. |
| `COOKIES_DIR` | Directory that holds the cookie files. |
+182
View File
@@ -0,0 +1,182 @@
set -u
PASS_N=0
FAIL_N=0
SKIP_N=0
RESULTS=""
FAIL_FAST="${FAIL_FAST:-1}"
ABORT_RUN=0
CHILD_PIDS=""
JOINER_PIDS=""
SINK_PID=""
SINK_PORT=""
SINK_FILE=""
SINK_WRAP="${SINK_WRAP:-}"
SINK_BIND="${SINK_BIND:-127.0.0.1}"
SINK_TARGET="${SINK_TARGET:-127.0.0.1}"
PROBE_HOST="${PROBE_HOST:-127.0.0.1}"
PORT_CURSOR="${PORT_BASE:-21080}"
PROBE_CAP=""
if command -v timeout >/dev/null 2>&1; then
PROBE_CAP="timeout 5"
elif command -v gtimeout >/dev/null 2>&1; then
PROBE_CAP="gtimeout 5"
fi
ALLOC_PORT=""
PROBE_SEQ=0
log() { printf '%s\n' "$*" >&2; }
die() {
log "FATAL: $*"
exit 2
}
require_bin() {
[ -x "$1" ] || die "missing binary $1 (run ./build-headless.sh)"
}
require_cmd() {
command -v "$1" >/dev/null 2>&1 || die "missing command $1"
}
track_pid() { CHILD_PIDS="$CHILD_PIDS $1"; }
proc_alive() { kill -0 "$1" 2>/dev/null; }
track_joiner() { JOINER_PIDS="$JOINER_PIDS $1"; }
alloc_port() {
while nc -z 127.0.0.1 "$PORT_CURSOR" 2>/dev/null; do
PORT_CURSOR=$((PORT_CURSOR + 1))
done
ALLOC_PORT="$PORT_CURSOR"
PORT_CURSOR=$((PORT_CURSOR + 1))
}
start_sink() {
alloc_port
SINK_PORT="$ALLOC_PORT"
SINK_FILE=$(mktemp -t e2e-sink.XXXXXX)
$SINK_WRAP ncat -l -k "$SINK_BIND" "$SINK_PORT" >"$SINK_FILE" 2>/dev/null &
SINK_PID=$!
track_pid "$SINK_PID"
sleep 1
}
stop_sink() {
[ -n "$SINK_PID" ] && kill "$SINK_PID" 2>/dev/null
SINK_PID=""
}
kill_joiners() {
for _p in $JOINER_PIDS; do kill "$_p" 2>/dev/null; done
for _p in $JOINER_PIDS; do wait "$_p" 2>/dev/null; done
JOINER_PIDS=""
}
cleanup() {
stop_sink
for _p in $CHILD_PIDS; do kill "$_p" 2>/dev/null; done
wait 2>/dev/null
}
now() { date +%s; }
wait_join_link() {
_lf="$1"
_to="$2"
_pid="${3:-}"
_end=$(($(now) + _to))
while [ "$(now)" -lt "$_end" ]; do
_l=$(grep -m1 "join_link:" "$_lf" 2>/dev/null | sed 's/.*join_link:[[:space:]]*//')
if [ -n "$_l" ]; then
echo "$_l"
return 0
fi
if [ -n "$_pid" ] && ! proc_alive "$_pid"; then
return 1
fi
sleep 1
done
return 1
}
wait_log_re() {
_lf="$1"
_re="$2"
_to="$3"
_pid="${4:-}"
_end=$(($(now) + _to))
while [ "$(now)" -lt "$_end" ]; do
grep -qE "$_re" "$_lf" 2>/dev/null && return 0
if [ -n "$_pid" ] && ! proc_alive "$_pid"; then
return 1
fi
sleep 1
done
return 1
}
wait_socks() {
_port="$1"
_to="$2"
_end=$(($(now) + _to))
while [ "$(now)" -lt "$_end" ]; do
nc -z "$PROBE_HOST" "$_port" 2>/dev/null && return 0
sleep 1
done
return 1
}
probe_once() {
_sp="$1"
_nonce="ping-$_sp-$PROBE_SEQ"
PROBE_SEQ=$((PROBE_SEQ + 1))
printf '%s\n' "$_nonce" | $PROBE_CAP ncat --send-only -w 4 --proxy "$PROBE_HOST:$_sp" --proxy-type socks5 "$SINK_TARGET" "$SINK_PORT" >/dev/null 2>&1
sleep 1
grep -q "$_nonce" "$SINK_FILE" 2>/dev/null
}
probe_ready() {
_sp="$1"
_to="$2"
_end=$(($(now) + _to))
while [ "$(now)" -lt "$_end" ]; do
probe_once "$_sp" && return 0
done
return 1
}
probe_dies() {
_sp="$1"
_to="$2"
_end=$(($(now) + _to))
while [ "$(now)" -lt "$_end" ]; do
probe_once "$_sp" || return 0
done
return 1
}
record() {
case "$1" in
PASS) PASS_N=$((PASS_N + 1)) ;;
FAIL)
FAIL_N=$((FAIL_N + 1))
[ "$FAIL_FAST" = "1" ] && ABORT_RUN=1
;;
SKIP) SKIP_N=$((SKIP_N + 1)) ;;
esac
RESULTS="$RESULTS
$1 $2"
}
summary() {
log ""
log "=== summary ==="
printf '%s\n' "$RESULTS" | sed '/^[[:space:]]*$/d' >&2
log ""
log "passed=$PASS_N failed=$FAIL_N skipped=$SKIP_N"
[ "$FAIL_N" -eq 0 ]
}
+84
View File
@@ -0,0 +1,84 @@
set -u
cookies_path() {
_p="$1"
case "$_p" in
telemost) _f="cookies-yandex.json" ;;
wbstream) _f="cookies-wbstream.json" ;;
dion) _f="cookies-dion.json" ;;
bitrix) _f="cookies-bitrix.json" ;;
*) _f="cookies-$_p.json" ;;
esac
_envname=$(printf 'COOKIES_%s' "$(echo "$_p" | tr 'a-z' 'A-Z')")
eval "_override=\${$_envname:-}"
if [ -n "$_override" ]; then
echo "$_override"
else
echo "${COOKIES_DIR:-$E2E_ROOT}/$_f"
fi
}
room_value() {
_envname=$(printf 'ROOM_%s' "$(echo "$1" | tr 'a-z' 'A-Z')")
eval "_v=\${$_envname:-}"
echo "$_v"
}
pf_select() {
PF_NAME="$1"
case "$1" in
telemost)
PF_CREATOR="$HEADLESS/telemost/headless-telemost-creator"
PF_JOINER="$HEADLESS/telemost-joiner/headless-telemost-joiner"
PF_LINK_FLAG="--tm-link"
PF_CREATOR_ROOM_FLAG="--tm-link"
PF_READY_RE="\[tm-ws\] Connected"
PF_CAPS="connect kcp dual kick"
;;
wbstream)
PF_CREATOR="$HEADLESS/wbstream/headless-wbstream-creator"
PF_JOINER="$HEADLESS/wbstream-joiner/headless-wbstream-joiner"
PF_LINK_FLAG="--room"
PF_CREATOR_ROOM_FLAG="--room"
PF_READY_RE="pub PC state: connected"
PF_CAPS="connect dc kcp dual kick"
;;
dion)
PF_CREATOR="$HEADLESS/dion/headless-dion-creator"
PF_JOINER="$HEADLESS/dion-joiner/headless-dion-joiner"
PF_LINK_FLAG="--room"
PF_CREATOR_ROOM_FLAG="--room"
PF_READY_RE="\[ice\] connected"
PF_CAPS="connect kick"
;;
bitrix)
PF_CREATOR="$HEADLESS/bitrix/headless-bitrix-creator"
PF_JOINER="$HEADLESS/bitrix-joiner/headless-bitrix-joiner"
PF_LINK_FLAG="--link"
PF_CREATOR_ROOM_FLAG="--room"
PF_READY_RE="pub PC state: connected"
PF_CAPS="connect dc kcp dual kick"
;;
*)
die "unknown platform: $1"
;;
esac
PF_COOKIES=$(cookies_path "$1")
PF_ROOM=$(room_value "$1")
}
pf_variant_flags() {
case "$1" in
dc) echo "--tunnel-mode dc" ;;
kcp) echo "--reliable" ;;
dual) echo "--dual-track" ;;
*) echo "" ;;
esac
}
pf_has_cap() {
for _c in $PF_CAPS; do
[ "$_c" = "$1" ] && return 0
done
return 1
}
+92
View File
@@ -0,0 +1,92 @@
#!/bin/sh
set -u
DIR="$(cd "$(dirname "$0")" && pwd)"
E2E_ROOT="$(cd "$DIR/../.." && pwd)"
HEADLESS="$E2E_ROOT/headless"
[ -f "$DIR/.env" ] && . "$DIR/.env"
. "$DIR/lib.sh"
. "$DIR/platforms.sh"
. "$DIR/scenarios.sh"
CREATE_TIMEOUT="${CREATE_TIMEOUT:-45}"
CONNECT_TIMEOUT="${CONNECT_TIMEOUT:-45}"
PROBE_TIMEOUT="${PROBE_TIMEOUT:-20}"
KICK_TIMEOUT="${KICK_TIMEOUT:-30}"
ALL_PLATFORMS="telemost wbstream dion bitrix"
ALL_SCENARIOS="connect dc kcp dual kick"
usage() {
cat >&2 <<EOF
Usage: $0 [platform...] [scenario...]
Live end-to-end harness: brings up a headless creator, connects one or more
headless joiners, and proves each tunnel by echoing a nonce through the joiner's
SOCKS5 to a local sink (no external network, no rate limits).
Platforms: $ALL_PLATFORMS
Scenarios: $ALL_SCENARIOS
connect one joiner, default video tunnel
dc one joiner, --tunnel-mode dc
kcp one joiner, --reliable (KCP)
dual one joiner, --dual-track
kick two joiners on one room, expect the first to be kicked
No args runs every applicable scenario on every platform. Unsupported
platform/scenario pairs are skipped.
Cookies: COOKIES_DIR (default repo root) holds cookies-<platform>.json, or set
COOKIES_<PLATFORM> to a explicit path. Missing cookies skip that platform.
Env: CREATE_TIMEOUT CONNECT_TIMEOUT PROBE_TIMEOUT KICK_TIMEOUT PORT_BASE
Examples:
$0
$0 bitrix
$0 wbstream dc kick
EOF
}
RUN_PLATFORMS=""
RUN_SCENARIOS=""
for _arg in "$@"; do
case "$_arg" in
-h | --help)
usage
exit 0
;;
telemost | wbstream | dion | bitrix)
RUN_PLATFORMS="$RUN_PLATFORMS $_arg"
;;
connect | dc | kcp | dual | kick)
RUN_SCENARIOS="$RUN_SCENARIOS $_arg"
;;
*)
log "unknown argument: $_arg"
usage
exit 2
;;
esac
done
[ -n "$RUN_PLATFORMS" ] || RUN_PLATFORMS="$ALL_PLATFORMS"
[ -n "$RUN_SCENARIOS" ] || RUN_SCENARIOS="$ALL_SCENARIOS"
require_cmd nc
require_cmd ncat
trap cleanup EXIT INT TERM
start_sink
log "sink on 127.0.0.1:$SINK_PORT"
for _pf in $RUN_PLATFORMS; do
run_platform "$_pf"
[ "$ABORT_RUN" = "1" ] && break
done
summary
+188
View File
@@ -0,0 +1,188 @@
set -u
CREATOR_WRAP="${CREATOR_WRAP:-}"
JOINER_WRAP="${JOINER_WRAP:-}"
JOINER_SOCKS_HOST="${JOINER_SOCKS_HOST:-127.0.0.1}"
run_platform() {
pf_select "$1"
require_bin "$PF_CREATOR"
require_bin "$PF_JOINER"
if [ ! -f "$PF_COOKIES" ]; then
log "=== $1 SKIP (cookies not found at $PF_COOKIES) ==="
record SKIP "$1 (cookies missing)"
return
fi
if [ -z "$PF_ROOM" ] && [ "${ALLOW_NEW_ROOMS:-0}" != "1" ]; then
log "=== $1 SKIP (no ROOM_$(echo "$1" | tr 'a-z' 'A-Z') set; refusing to create a new room. Set it in .env or pass ALLOW_NEW_ROOMS=1) ==="
record SKIP "$1 (no room)"
return
fi
if ! start_creator; then
record FAIL "$1 (creator)"
return
fi
for _s in $RUN_SCENARIOS; do
if ! proc_alive "$CREATOR_PID"; then
log "=== $1 ABORT: creator died mid-run ==="
record FAIL "$1 (creator died)"
break
fi
case "$_s" in
connect) sc_connect ;;
dc) sc_params dc ;;
kcp) sc_params kcp ;;
dual) sc_params dual ;;
kick) sc_kick ;;
esac
kill_joiners
[ "$ABORT_RUN" = "1" ] && {
log "=== $1 ABORT: scenario failed (fail-fast); stopping ==="
break
}
sleep 1
done
stop_creator
}
start_creator() {
CREATOR_LOG=$(mktemp -t e2e-creator.XXXXXX)
_room_args=""
if [ -n "$PF_ROOM" ]; then
_room_args="$PF_CREATOR_ROOM_FLAG $PF_ROOM"
log " reusing room: $PF_ROOM"
fi
$CREATOR_WRAP "$PF_CREATOR" --cookies "$PF_COOKIES" $_room_args --allow-private-dst >"$CREATOR_LOG" 2>&1 &
CREATOR_PID=$!
track_pid "$CREATOR_PID"
if ! JOIN_LINK=$(wait_join_link "$CREATOR_LOG" "$CREATE_TIMEOUT" "$CREATOR_PID"); then
if proc_alive "$CREATOR_PID"; then
log " creator did not print join_link in ${CREATE_TIMEOUT}s"
else
log " creator exited before join_link (fatal)"
fi
tail -15 "$CREATOR_LOG" >&2
return 1
fi
log " join_link=$JOIN_LINK"
if ! wait_log_re "$CREATOR_LOG" "$PF_READY_RE" "$CREATE_TIMEOUT" "$CREATOR_PID"; then
if proc_alive "$CREATOR_PID"; then
log " creator did not reach ready state ($PF_READY_RE) in ${CREATE_TIMEOUT}s"
else
log " creator exited before ready state (fatal)"
fi
tail -15 "$CREATOR_LOG" >&2
return 1
fi
log " creator up on SFU, room stays for all scenarios"
sleep 1
return 0
}
stop_creator() {
[ -n "${CREATOR_PID:-}" ] && kill "$CREATOR_PID" 2>/dev/null
CREATOR_PID=""
}
dump_logs() {
log " --- creator tail ---"
tail -20 "$CREATOR_LOG" >&2
log " --- joiner tail ---"
tail -20 "$JOINER_LOG" >&2
}
dump_kick_logs() {
log " --- creator kick events ---"
grep -nE '\[kick\]|kicked previous|active call guest|kick failed|usersAnswered|kicked stale peer|kick_one' "$CREATOR_LOG" 2>/dev/null | tail -20 >&2
log " --- joiner A kick-watch ---"
grep -nE 'subws2|pull config|kick-detect|kicked from|shutting down|chatUserLeave|you_kicked|server kicked' "$_log_a" 2>/dev/null | tail -20 >&2
}
start_joiner() {
_variant="$1"
alloc_port
JOINER_PORT="$ALLOC_PORT"
JOINER_LOG=$(mktemp -t e2e-joiner.XXXXXX)
_flags=$(pf_variant_flags "$_variant")
$JOINER_WRAP "$PF_JOINER" "$PF_LINK_FLAG" "$JOIN_LINK" --socks-host "$JOINER_SOCKS_HOST" --socks-port "$JOINER_PORT" $_flags >"$JOINER_LOG" 2>&1 &
JOINER_PID=$!
track_pid "$JOINER_PID"
track_joiner "$JOINER_PID"
}
joiner_up() {
wait_socks "$1" "$CONNECT_TIMEOUT" && probe_ready "$1" "$PROBE_TIMEOUT"
}
sc_connect() {
_name="$PF_NAME/connect"
log "=== $_name ==="
start_joiner connect
if joiner_up "$JOINER_PORT"; then
record PASS "$_name"
else
log " joiner did not carry traffic"
dump_logs
record FAIL "$_name"
fi
}
sc_params() {
_variant="$1"
_name="$PF_NAME/params:$_variant"
if ! pf_has_cap "$_variant"; then
log "=== $_name SKIP (unsupported) ==="
record SKIP "$_name"
return
fi
log "=== $_name ==="
start_joiner "$_variant"
if joiner_up "$JOINER_PORT"; then
record PASS "$_name"
else
log " joiner did not carry traffic"
dump_logs
record FAIL "$_name"
fi
}
sc_kick() {
_name="$PF_NAME/kick"
if ! pf_has_cap kick; then
log "=== $_name SKIP ==="
record SKIP "$_name"
return
fi
log "=== $_name ==="
_kv=connect
pf_has_cap dc && _kv=dc
start_joiner "$_kv"
_port_a="$JOINER_PORT"
_log_a="$JOINER_LOG"
if ! joiner_up "$_port_a"; then
log " joiner A never carried traffic; tail:"
tail -15 "$_log_a" >&2
dump_kick_logs
record FAIL "$_name (A up)"
return
fi
log " joiner A up on $_port_a, joining second joiner"
start_joiner "$_kv"
_port_b="$JOINER_PORT"
_log_b="$JOINER_LOG"
if ! joiner_up "$_port_b"; then
log " joiner B never carried traffic; tail:"
tail -15 "$_log_b" >&2
dump_kick_logs
record FAIL "$_name (B up)"
return
fi
log " joiner B up on $_port_b, expecting A to be kicked"
if probe_dies "$_port_a" "$KICK_TIMEOUT" && probe_once "$_port_b"; then
record PASS "$_name"
else
log " expected A kicked while B holds the tunnel"
dump_kick_logs
record FAIL "$_name"
fi
}
+13
View File
@@ -0,0 +1,13 @@
FROM debian:bookworm-slim
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
iproute2 iptables ncat ca-certificates procps \
&& rm -rf /var/lib/apt/lists/*
COPY work /work
RUN chmod +x /work/headless/*/headless-* \
/work/headless/tests/*.sh \
/work/headless/tests/stand/*.sh
CMD ["sleep", "infinity"]
+68
View File
@@ -0,0 +1,68 @@
#!/bin/sh
set -u
DIR="$(cd "$(dirname "$0")" && pwd)"
E2E_ROOT="${E2E_ROOT:-/work}"
HEADLESS="$E2E_ROOT/headless"
E2E_DIR="$HEADLESS/tests"
[ -f "$E2E_DIR/.env" ] && . "$E2E_DIR/.env"
. "$E2E_DIR/lib.sh"
. "$E2E_DIR/platforms.sh"
. "$E2E_DIR/scenarios.sh"
. "$DIR/netns.sh"
CREATE_TIMEOUT="${CREATE_TIMEOUT:-45}"
CONNECT_TIMEOUT="${CONNECT_TIMEOUT:-45}"
PROBE_TIMEOUT="${PROBE_TIMEOUT:-25}"
KICK_TIMEOUT="${KICK_TIMEOUT:-30}"
ALL_PLATFORMS="telemost wbstream dion bitrix"
ALL_SCENARIOS="connect dc kcp dual kick"
RUN_PLATFORMS=""
RUN_SCENARIOS=""
for _arg in "$@"; do
case "$_arg" in
telemost | wbstream | dion | bitrix) RUN_PLATFORMS="$RUN_PLATFORMS $_arg" ;;
connect | dc | kcp | dual | kick) RUN_SCENARIOS="$RUN_SCENARIOS $_arg" ;;
*)
log "unknown argument: $_arg"
exit 2
;;
esac
done
[ -n "$RUN_PLATFORMS" ] || RUN_PLATFORMS="$ALL_PLATFORMS"
[ -n "$RUN_SCENARIOS" ] || RUN_SCENARIOS="$ALL_SCENARIOS"
require_cmd nc
require_cmd ncat
require_cmd ip
require_cmd iptables
CREATOR_WRAP="ip netns exec creator"
JOINER_WRAP="ip netns exec joiner"
JOINER_SOCKS_HOST="0.0.0.0"
PROBE_HOST="10.201.2.2"
SINK_WRAP="ip netns exec creator"
SINK_BIND="127.0.0.1"
SINK_TARGET="127.0.0.1"
cleanup_all() {
cleanup
teardown_ns
}
trap cleanup_all EXIT INT TERM
setup_ns creator 1
setup_ns joiner 2
start_sink
log "netns creator=10.201.1.2 joiner=10.201.2.2 sink=creator:$SINK_PORT"
for _pf in $RUN_PLATFORMS; do
run_platform "$_pf"
[ "$ABORT_RUN" = "1" ] && break
done
summary
+37
View File
@@ -0,0 +1,37 @@
set -u
NETNS_CREATED=""
setup_ns() {
_name="$1"
_sub="$2"
_gw="10.201.$_sub.1"
_addr="10.201.$_sub.2"
ip netns add "$_name"
ip link add "veth-$_name" type veth peer name "peer-$_name"
ip link set "peer-$_name" netns "$_name"
ip addr add "$_gw/30" dev "veth-$_name"
ip link set "veth-$_name" up
ip netns exec "$_name" ip link set "peer-$_name" name eth0
ip netns exec "$_name" ip link set lo up
ip netns exec "$_name" ip addr add "$_addr/30" dev eth0
ip netns exec "$_name" ip link set eth0 up
ip netns exec "$_name" ip route add default via "$_gw"
iptables -t nat -A POSTROUTING -s "$_addr/32" -j MASQUERADE
mkdir -p "/etc/netns/$_name"
_ns=$(grep '^nameserver' /etc/resolv.conf | grep -v ' 127\.' || true)
[ -n "$_ns" ] || _ns="nameserver 1.1.1.1"
printf '%s\n' "$_ns" >"/etc/netns/$_name/resolv.conf"
NETNS_CREATED="$NETNS_CREATED $_name:$_addr"
}
teardown_ns() {
for _entry in $NETNS_CREATED; do
_name="${_entry%%:*}"
_addr="${_entry#*:}"
iptables -t nat -D POSTROUTING -s "$_addr/32" -j MASQUERADE 2>/dev/null
ip netns delete "$_name" 2>/dev/null
rm -rf "/etc/netns/$_name"
done
NETNS_CREATED=""
}
+89
View File
@@ -0,0 +1,89 @@
#!/bin/sh
set -eu
DIR="$(cd "$(dirname "$0")" && pwd)"
REPO="$(cd "$DIR/../../.." && pwd)"
E2E="$REPO/headless/tests"
CTX="$DIR/.context"
IMAGE=wlb-e2e-stand
COMPONENTS="\
telemost/headless-telemost-creator \
wbstream/headless-wbstream-creator \
dion/headless-dion-creator \
bitrix/headless-bitrix-creator \
telemost-joiner/headless-telemost-joiner \
wbstream-joiner/headless-wbstream-joiner \
dion-joiner/headless-dion-joiner \
bitrix-joiner/headless-bitrix-joiner"
usage() {
cat >&2 <<EOF
Usage: stand.sh build | run [platform...] [scenario...] | sh
Dockerized live e2e: each of creator and joiner runs in its own network
namespace (distinct IP), so same-host WebRTC ICE does not collide. Traffic is
proved by echoing a nonce through the joiner's SOCKS5 to a sink on the creator's
loopback - no external network, no rate limits.
build cross-build linux binaries, stage cookies, docker build
run run the netns harness in a privileged container
sh drop into a shell in the container for debugging
Platforms: telemost wbstream dion bitrix (VK has no headless SOCKS joiner)
Scenarios: connect dc kcp dual kick
Cookies are taken from cookies-<platform>.json at the repo root at build time.
Rebuild after refreshing cookies. Examples:
stand.sh build
stand.sh run
stand.sh run bitrix dc kick
EOF
exit 1
}
build_context() {
arch=$(docker version --format '{{.Server.Arch}}' 2>/dev/null || echo arm64)
rm -rf "$CTX"
mkdir -p "$CTX/work/headless/tests/stand"
for spec in $COMPONENTS; do
d="${spec%%/*}"
b="${spec##*/}"
mkdir -p "$CTX/work/headless/$d"
echo "building $b (linux/$arch)..."
GOOS=linux GOARCH="$arch" CGO_ENABLED=0 \
go -C "$REPO/headless/$d" build -trimpath -ldflags="-s -w" -o "$CTX/work/headless/$d/$b" .
done
cp "$E2E/lib.sh" "$E2E/platforms.sh" "$E2E/scenarios.sh" "$CTX/work/headless/tests/"
[ -f "$E2E/.env" ] && cp "$E2E/.env" "$CTX/work/headless/tests/"
cp "$DIR/netns.sh" "$DIR/netns-run.sh" "$CTX/work/headless/tests/stand/"
cp "$DIR/Dockerfile" "$CTX/Dockerfile"
}
case "${1:-}" in
build)
build_context
docker build -t "$IMAGE" "$CTX"
echo "built $IMAGE"
;;
run)
shift
cookie_mounts=""
for c in vk yandex wbstream dion bitrix; do
f="$REPO/cookies-$c.json"
[ -f "$f" ] && cookie_mounts="$cookie_mounts -v $f:/cookies/cookies-$c.json"
done
docker run --rm --cap-add=NET_ADMIN --cap-add=SYS_ADMIN \
-e FAIL_FAST="${FAIL_FAST:-1}" \
-e COOKIES_DIR=/cookies \
$cookie_mounts \
"$IMAGE" /work/headless/tests/stand/netns-run.sh "$@"
;;
sh)
docker run --rm -it --cap-add=NET_ADMIN --cap-add=SYS_ADMIN \
"$IMAGE" /bin/bash
;;
*)
usage
;;
esac
@@ -1,93 +0,0 @@
#!/bin/sh
# Smoke test for headless-telemost-creator -tm-link: create a conference,
# then a second creator joins the same conference URI.
#
# Usage: ./test-telemost-join-existing.sh <path-to-cookies.json>
set -u
ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
CREATOR="$ROOT/headless/telemost/headless-telemost-creator"
if [ $# -lt 1 ]; then
echo "Usage: $0 <path-to-cookies.json>" >&2
exit 2
fi
COOKIES="$1"
SETTLE_TIMEOUT=30
[ -x "$CREATOR" ] || { echo "FAIL: $CREATOR not built, run ./build-headless.sh" >&2; exit 2; }
[ -f "$COOKIES" ] || { echo "FAIL: cookies not found at: $COOKIES" >&2; exit 2; }
echo "cookies: $COOKIES"
PHASE1_LOG=$(mktemp -t tm-create.XXXXXX.log)
PHASE2_LOG=$(mktemp -t tm-join.XXXXXX.log)
P1_PID=""
P2_PID=""
cleanup() {
[ -n "$P2_PID" ] && kill "$P2_PID" 2>/dev/null
[ -n "$P1_PID" ] && kill "$P1_PID" 2>/dev/null
wait 2>/dev/null
}
trap cleanup EXIT INT TERM
echo "=== phase 1: create conference ==="
"$CREATOR" -cookies "$COOKIES" > "$PHASE1_LOG" 2>&1 &
P1_PID=$!
waited=0
JOIN_LINK=""
while [ "$waited" -lt "$SETTLE_TIMEOUT" ]; do
JOIN_LINK=$(grep -m1 -oE "https://telemost\.yandex\.[a-z]+/j/[A-Za-z0-9_-]+" "$PHASE1_LOG" | head -1)
[ -n "$JOIN_LINK" ] && break
if ! kill -0 "$P1_PID" 2>/dev/null; then
echo "FAIL: phase 1 process died" >&2
tail -20 "$PHASE1_LOG" >&2
exit 1
fi
sleep 1
waited=$((waited + 1))
done
if [ -z "$JOIN_LINK" ]; then
echo "FAIL: phase 1 did not print join_link within ${SETTLE_TIMEOUT}s" >&2
tail -20 "$PHASE1_LOG" >&2
exit 1
fi
echo "phase 1 join_link: $JOIN_LINK"
sleep 3
echo ""
echo "=== phase 2: join existing conference via -tm-link ==="
"$CREATOR" -cookies "$COOKIES" -tm-link "$JOIN_LINK" > "$PHASE2_LOG" 2>&1 &
P2_PID=$!
waited=0
while [ "$waited" -lt "$SETTLE_TIMEOUT" ]; do
if grep -q "media_server=" "$PHASE2_LOG"; then
break
fi
if grep -qE "Failed to join existing conference|empty conference URI" "$PHASE2_LOG"; then
break
fi
if ! kill -0 "$P2_PID" 2>/dev/null; then
break
fi
sleep 1
waited=$((waited + 1))
done
echo ""
echo "--- phase 2 log tail ---"
tail -25 "$PHASE2_LOG"
if grep -q "media_server=" "$PHASE2_LOG" && grep -q "Joining existing conference" "$PHASE2_LOG"; then
echo ""
echo "PASS: phase 2 joined the existing conference"
exit 0
fi
echo ""
echo "FAIL: phase 2 did not reach media_server stage" >&2
exit 1
-93
View File
@@ -1,93 +0,0 @@
#!/bin/sh
# Smoke test: headless-telemost-creator creates a conference, headless-telemost-joiner
# joins it via -tm-link and exposes a SOCKS5 listener.
#
# Usage: ./test-telemost-joiner.sh <path-to-cookies.json>
set -u
ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
CREATOR="$ROOT/headless/telemost/headless-telemost-creator"
JOINER="$ROOT/headless/telemost-joiner/headless-telemost-joiner"
SOCKS_PORT=11080
SETTLE_TIMEOUT=45
if [ $# -lt 1 ]; then
echo "Usage: $0 <path-to-cookies.json>" >&2
exit 2
fi
COOKIES="$1"
[ -x "$CREATOR" ] || { echo "FAIL: $CREATOR not built (run ./build-headless.sh)" >&2; exit 2; }
[ -x "$JOINER" ] || { echo "FAIL: $JOINER not built (run ./build-headless.sh)" >&2; exit 2; }
[ -f "$COOKIES" ] || { echo "FAIL: cookies not found at: $COOKIES" >&2; exit 2; }
PHASE1_LOG=$(mktemp -t tm-create.XXXXXX.log)
PHASE2_LOG=$(mktemp -t tm-joiner.XXXXXX.log)
P1_PID=""
P2_PID=""
cleanup() {
[ -n "$P2_PID" ] && kill "$P2_PID" 2>/dev/null
[ -n "$P1_PID" ] && kill "$P1_PID" 2>/dev/null
wait 2>/dev/null
}
trap cleanup EXIT INT TERM
echo "=== phase 1: create conference ==="
"$CREATOR" -cookies "$COOKIES" > "$PHASE1_LOG" 2>&1 &
P1_PID=$!
waited=0
JOIN_LINK=""
while [ "$waited" -lt "$SETTLE_TIMEOUT" ]; do
JOIN_LINK=$(grep -m1 -oE "https://telemost\.yandex\.[a-z]+/j/[A-Za-z0-9_-]+" "$PHASE1_LOG" | head -1)
[ -n "$JOIN_LINK" ] && break
if ! kill -0 "$P1_PID" 2>/dev/null; then
echo "FAIL: phase 1 process died" >&2
tail -20 "$PHASE1_LOG" >&2
exit 1
fi
sleep 1
waited=$((waited + 1))
done
if [ -z "$JOIN_LINK" ]; then
echo "FAIL: phase 1 did not print join_link within ${SETTLE_TIMEOUT}s" >&2
tail -20 "$PHASE1_LOG" >&2
exit 1
fi
echo "phase 1 join_link: $JOIN_LINK"
sleep 3
echo ""
echo "=== phase 2: join via headless-telemost-joiner ==="
"$JOINER" -tm-link "$JOIN_LINK" -socks-port "$SOCKS_PORT" > "$PHASE2_LOG" 2>&1 &
P2_PID=$!
waited=0
while [ "$waited" -lt "$SETTLE_TIMEOUT" ]; do
if grep -q "TUNNEL CONNECTED" "$PHASE2_LOG"; then
break
fi
if ! kill -0 "$P2_PID" 2>/dev/null; then
break
fi
sleep 1
waited=$((waited + 1))
done
echo ""
echo "--- phase 2 log tail ---"
tail -25 "$PHASE2_LOG"
if grep -q "TUNNEL CONNECTED" "$PHASE2_LOG" && grep -q "socks5 -> 127.0.0.1:${SOCKS_PORT}" "$PHASE2_LOG"; then
echo ""
echo "PASS: joiner reached TUNNEL CONNECTED on socks port ${SOCKS_PORT}"
exit 0
fi
echo ""
echo "FAIL: joiner did not reach TUNNEL CONNECTED within ${SETTLE_TIMEOUT}s" >&2
exit 1
-116
View File
@@ -1,116 +0,0 @@
#!/bin/sh
set -u
ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
CREATOR="$ROOT/headless/telemost/headless-telemost-creator"
JOINER="$ROOT/headless/telemost-joiner/headless-telemost-joiner"
RATES="${RATES:-0 62500 125000 250000 625000}"
PHASE_SECS="${PHASE_SECS:-100}"
SOCKS_PORT="${SOCKS_PORT:-11080}"
SINK_PORT="${SINK_PORT:-19099}"
SETTLE_TIMEOUT="${SETTLE_TIMEOUT:-60}"
if [ $# -lt 2 ]; then
echo "Usage: $0 <cookies.json> <telemost-join-link>" >&2
exit 2
fi
COOKIES="$1"
TM_LINK="$2"
[ -x "$CREATOR" ] || { echo "FAIL: $CREATOR not built (run ./build-headless.sh)" >&2; exit 2; }
[ -x "$JOINER" ] || { echo "FAIL: $JOINER not built (run ./build-headless.sh)" >&2; exit 2; }
[ -f "$COOKIES" ] || { echo "FAIL: cookies not found: $COOKIES" >&2; exit 2; }
command -v ncat >/dev/null 2>&1 || { echo "FAIL: ncat not found (brew install nmap)" >&2; exit 2; }
CREATOR_LOG=$(mktemp -t tm-reap-creator.XXXXXX.log)
JOINER_LOG=$(mktemp -t tm-reap-joiner.XXXXXX.log)
C_PID=""; J_PID=""; SINK_PID=""
cleanup() {
[ -n "$SINK_PID" ] && kill "$SINK_PID" 2>/dev/null
[ -n "$J_PID" ] && kill "$J_PID" 2>/dev/null
[ -n "$C_PID" ] && kill "$C_PID" 2>/dev/null
wait 2>/dev/null
}
trap cleanup EXIT INT TERM
echo "room: $TM_LINK"
echo "rates: $RATES phase: ${PHASE_SECS}s socks: $SOCKS_PORT sink: $SINK_PORT"
echo "=== creator joins named room ==="
"$CREATOR" -cookies "$COOKIES" -tm-link "$TM_LINK" > "$CREATOR_LOG" 2>&1 &
C_PID=$!
echo "=== joiner joins named room, exposes SOCKS5 ==="
"$JOINER" -tm-link "$TM_LINK" -socks-port "$SOCKS_PORT" > "$JOINER_LOG" 2>&1 &
J_PID=$!
waited=0
while [ "$waited" -lt "$SETTLE_TIMEOUT" ]; do
grep -q "TUNNEL CONNECTED" "$JOINER_LOG" && break
kill -0 "$C_PID" 2>/dev/null || { echo "FAIL: creator died" >&2; tail -20 "$CREATOR_LOG" >&2; exit 1; }
kill -0 "$J_PID" 2>/dev/null || { echo "FAIL: joiner died" >&2; tail -20 "$JOINER_LOG" >&2; exit 1; }
sleep 1; waited=$((waited + 1))
done
grep -q "TUNNEL CONNECTED" "$JOINER_LOG" || { echo "FAIL: no TUNNEL CONNECTED in ${SETTLE_TIMEOUT}s" >&2; tail -25 "$JOINER_LOG" >&2; exit 1; }
echo "tunnel up."
# discard sink reached through the tunnel egress; creator and joiner share this host's loopback
ncat -k -l --recv-only 127.0.0.1 "$SINK_PORT" > /dev/null 2>&1 &
SINK_PID=$!
sleep 1
# emit ~rate bytes/sec into stdout for dur seconds, in 10 chunks/sec (coarse token bucket, no pv dep)
pump_rate() {
rate=$1; dur=$2
[ "$rate" -le 0 ] && { sleep "$dur"; return; }
chunk=$((rate / 10)); [ "$chunk" -lt 1 ] && chunk=1
end=$(( $(date +%s) + dur ))
while [ "$(date +%s)" -lt "$end" ]; do
dd if=/dev/zero bs="$chunk" count=1 2>/dev/null
sleep 0.1
done
}
# count reap markers currently in both logs
reap_count() {
c1=$(grep -cE "\[bind\] UNBOUND|forcing reconnect: slot binding killed" "$JOINER_LOG" 2>/dev/null || echo 0)
c2=$(grep -cE "\[bind\] UNBOUND|forcing reconnect: slot binding killed" "$CREATOR_LOG" 2>/dev/null || echo 0)
echo $((c1 + c2))
}
echo ""
echo "=== reap sweep ==="
printf "%-10s %-14s %-12s\n" "rate_Bps" "first_reap_s" "reaps_in_phase"
RESULTS=""
for RATE in $RATES; do
base=$(reap_count)
start=$(date +%s)
# drive the load in the background so we can poll for the reap during the phase
( pump_rate "$RATE" "$PHASE_SECS" | ncat --proxy 127.0.0.1:"$SOCKS_PORT" --proxy-type socks5 127.0.0.1 "$SINK_PORT" ) >/dev/null 2>&1 &
LOAD_PID=$!
first_reap="-"
while kill -0 "$LOAD_PID" 2>/dev/null; do
if [ "$first_reap" = "-" ] && [ "$(reap_count)" -gt "$base" ]; then
first_reap=$(( $(date +%s) - start ))
fi
sleep 1
done
wait "$LOAD_PID" 2>/dev/null
# one final check after the phase ends
if [ "$first_reap" = "-" ] && [ "$(reap_count)" -gt "$base" ]; then
first_reap=$(( $(date +%s) - start ))
fi
total=$(( $(reap_count) - base ))
printf "%-10s %-14s %-12s\n" "$RATE" "$first_reap" "$total"
RESULTS="$RESULTS$RATE=$first_reap,${total} "
done
echo ""
echo "--- joiner reap lines ---"
grep -nE "\[bind\] (BOUND|UNBOUND)|forcing reconnect" "$JOINER_LOG" | tail -20
echo ""
echo "summary (rate_Bps=first_reap_s,reaps): $RESULTS"
echo "logs: creator=$CREATOR_LOG joiner=$JOINER_LOG"
-149
View File
@@ -1,149 +0,0 @@
#!/bin/sh
# End-to-end test for creator --upstream-socks, on Telemost.
#
# A telemost creator JOINS an existing conference (your call link, never created
# here) and a telemost joiner joins the same conference to form the tunnel. We run
# the pair twice - once with direct egress, once with -upstream-socks - and assert
# the joiner's public egress IP CHANGES. A changed IP proves the joiner's traffic
# left through the upstream SOCKS5 (your VPN client -> VPS) instead of this host.
#
# Needs: a real upstream SOCKS5 proxy whose exit IP differs from this machine
# (an actual VPN client pointing at a VPS), plus Yandex cookies and a live call link.
#
# Usage:
# UPSTREAM_SOCKS=127.0.0.1:1080 ./test-upstream-socks.sh <cookies-yandex.json> <tm-link>
# UPSTREAM_SOCKS=127.0.0.1:1080 UPSTREAM_USER=u UPSTREAM_PASS=p \
# ./test-upstream-socks.sh <cookies-yandex.json> https://telemost.yandex.ru/j/<id>
set -u
ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
CREATOR="$ROOT/headless/telemost/headless-telemost-creator"
JOINER="$ROOT/headless/telemost-joiner/headless-telemost-joiner"
SOCKS_PORT=11080
IP_URL="https://api.ipify.org"
SETTLE_TIMEOUT=45
PROBE_TIMEOUT=15
if [ $# -lt 2 ]; then
echo "Usage: UPSTREAM_SOCKS=host:port $0 <cookies-yandex.json> <tm-link>" >&2
exit 2
fi
COOKIES="$1"
TM_LINK="$2"
if [ -z "${UPSTREAM_SOCKS:-}" ]; then
echo "FAIL: set UPSTREAM_SOCKS=host:port (a real SOCKS5 proxy / VPN client whose exit IP differs from this host)" >&2
exit 2
fi
[ -x "$CREATOR" ] || { echo "FAIL: missing $CREATOR (run ./build-headless.sh first)" >&2; exit 2; }
[ -x "$JOINER" ] || { echo "FAIL: missing $JOINER (run ./build-headless.sh first)" >&2; exit 2; }
[ -f "$COOKIES" ] || { echo "FAIL: cookies not found at: $COOKIES" >&2; exit 2; }
echo "cookies=$COOKIES tm-link=$TM_LINK upstream=$UPSTREAM_SOCKS"
CREATOR_PID=""
JOINER_PID=""
kill_pair() {
[ -n "$JOINER_PID" ] && kill "$JOINER_PID" 2>/dev/null
[ -n "$CREATOR_PID" ] && kill "$CREATOR_PID" 2>/dev/null
wait 2>/dev/null
JOINER_PID=""
CREATOR_PID=""
}
trap kill_pair EXIT INT TERM
# run_chain <label> [extra creator args...] -> prints the joiner's egress IP on stdout
run_chain() {
label="$1"
shift
clog=$(mktemp -t up-c.XXXXXX.log)
jlog=$(mktemp -t up-j.XXXXXX.log)
"$CREATOR" -cookies "$COOKIES" -tm-link "$TM_LINK" "$@" >"$clog" 2>&1 &
CREATOR_PID=$!
w=0
while [ "$w" -lt "$SETTLE_TIMEOUT" ]; do
grep -q "media_server=" "$clog" && break
if ! kill -0 "$CREATOR_PID" 2>/dev/null; then
echo "FAIL[$label]: creator died before joining the conference" >&2
tail -20 "$clog" >&2
kill_pair
return 1
fi
sleep 1
w=$((w + 1))
done
if ! grep -q "media_server=" "$clog"; then
echo "FAIL[$label]: creator did not join the conference in ${SETTLE_TIMEOUT}s" >&2
tail -20 "$clog" >&2
kill_pair
return 1
fi
sleep 3
"$JOINER" -tm-link "$TM_LINK" -socks-port "$SOCKS_PORT" >"$jlog" 2>&1 &
JOINER_PID=$!
w=0
while [ "$w" -lt "$SETTLE_TIMEOUT" ]; do
grep -q "TUNNEL CONNECTED" "$jlog" && break
if ! kill -0 "$JOINER_PID" 2>/dev/null; then
break
fi
sleep 1
w=$((w + 1))
done
if ! grep -q "TUNNEL CONNECTED" "$jlog"; then
echo "FAIL[$label]: joiner never reached TUNNEL CONNECTED in ${SETTLE_TIMEOUT}s" >&2
tail -20 "$jlog" >&2
kill_pair
return 1
fi
w=0
while [ "$w" -lt 10 ]; do
nc -z 127.0.0.1 "$SOCKS_PORT" 2>/dev/null && break
sleep 1
w=$((w + 1))
done
ip=$(curl --socks5-hostname "127.0.0.1:$SOCKS_PORT" -m "$PROBE_TIMEOUT" -s "$IP_URL")
kill_pair
echo "$ip"
}
echo "=== baseline: direct egress ==="
DIRECT_IP=$(run_chain direct) || exit 1
echo "direct_ip=$DIRECT_IP"
# Let the fixed SOCKS port free up before the second pair.
sleep 2
echo "=== upstream: -upstream-socks $UPSTREAM_SOCKS ==="
set -- -upstream-socks "$UPSTREAM_SOCKS"
[ -n "${UPSTREAM_USER:-}" ] && set -- "$@" -upstream-user "$UPSTREAM_USER"
[ -n "${UPSTREAM_PASS:-}" ] && set -- "$@" -upstream-pass "$UPSTREAM_PASS"
UPSTREAM_IP=$(run_chain upstream "$@") || exit 1
echo "upstream_ip=$UPSTREAM_IP"
case "$DIRECT_IP" in
*.*) ;;
*)
echo "FAIL: no direct egress IP (baseline chain broken)" >&2
exit 1
;;
esac
case "$UPSTREAM_IP" in
*.*) ;;
*)
echo "FAIL: no egress IP via upstream - is $UPSTREAM_SOCKS reachable and does its SOCKS5 inbound work?" >&2
exit 1
;;
esac
if [ "$DIRECT_IP" = "$UPSTREAM_IP" ]; then
echo "FAIL: egress IP unchanged ($UPSTREAM_IP) - joiner traffic did NOT go through the upstream" >&2
exit 1
fi
echo "PASS: egress moved from $DIRECT_IP (this host) to $UPSTREAM_IP (via $UPSTREAM_SOCKS)"
-93
View File
@@ -1,93 +0,0 @@
#!/bin/sh
# Smoke test for -vk-link: create a call, then join it via the new flag.
#
# Usage: ./test-vk-join-existing.sh <path-to-cookies.json>
set -u
ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
CREATOR="$ROOT/headless/vk/headless-vk-creator"
if [ $# -lt 1 ]; then
echo "Usage: $0 <path-to-cookies.json>" >&2
exit 2
fi
COOKIES="$1"
SETTLE_TIMEOUT=25
[ -x "$CREATOR" ] || { echo "FAIL: $CREATOR not built, run ./build-headless.sh" >&2; exit 2; }
[ -f "$COOKIES" ] || { echo "FAIL: cookies not found at: $COOKIES" >&2; exit 2; }
echo "cookies: $COOKIES"
PHASE1_LOG=$(mktemp -t vk-create.XXXXXX.log)
PHASE2_LOG=$(mktemp -t vk-join.XXXXXX.log)
P1_PID=""
P2_PID=""
cleanup() {
[ -n "$P2_PID" ] && kill "$P2_PID" 2>/dev/null
[ -n "$P1_PID" ] && kill "$P1_PID" 2>/dev/null
wait 2>/dev/null
}
trap cleanup EXIT INT TERM
echo "=== phase 1: create call ==="
"$CREATOR" -cookies "$COOKIES" > "$PHASE1_LOG" 2>&1 &
P1_PID=$!
waited=0
JOIN_LINK=""
while [ "$waited" -lt "$SETTLE_TIMEOUT" ]; do
JOIN_LINK=$(grep -m1 -oE "https://vk\.com/call/join/[A-Za-z0-9_-]+" "$PHASE1_LOG")
[ -n "$JOIN_LINK" ] && break
if ! kill -0 "$P1_PID" 2>/dev/null; then
echo "FAIL: phase 1 process died" >&2
tail -20 "$PHASE1_LOG" >&2
exit 1
fi
sleep 1
waited=$((waited + 1))
done
if [ -z "$JOIN_LINK" ]; then
echo "FAIL: phase 1 did not print join_link within ${SETTLE_TIMEOUT}s" >&2
tail -20 "$PHASE1_LOG" >&2
exit 1
fi
echo "phase 1 join_link: $JOIN_LINK"
# Wait a beat so the call is fully joined on VK's side before phase 2 starts.
sleep 3
echo ""
echo "=== phase 2: join existing call via -vk-link ==="
"$CREATOR" -cookies "$COOKIES" -vk-link "$JOIN_LINK" > "$PHASE2_LOG" 2>&1 &
P2_PID=$!
waited=0
while [ "$waited" -lt "$SETTLE_TIMEOUT" ]; do
if grep -q "vk-ws] Connected" "$PHASE2_LOG"; then
break
fi
if grep -qE "Failed to join existing call|empty WS endpoint|empty session_key" "$PHASE2_LOG"; then
break
fi
if ! kill -0 "$P2_PID" 2>/dev/null; then
break
fi
sleep 1
waited=$((waited + 1))
done
echo ""
echo "--- phase 2 log tail ---"
tail -25 "$PHASE2_LOG"
if grep -q "vk-ws] Connected" "$PHASE2_LOG"; then
echo ""
echo "PASS: phase 2 joined the existing call (got vk-ws connection)"
exit 0
fi
echo ""
echo "FAIL: phase 2 did not reach vk-ws connection" >&2
exit 1
@@ -1,87 +0,0 @@
#!/bin/sh
# Smoke test for headless-wbstream-creator -room: create a room, then a second
# creator joins the same room id.
set -u
ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
CREATOR="$ROOT/headless/wbstream/headless-wbstream-creator"
SETTLE_TIMEOUT=25
[ -x "$CREATOR" ] || { echo "FAIL: $CREATOR not built (run ./build-headless.sh)" >&2; exit 2; }
PHASE1_LOG=$(mktemp -t wb-create.XXXXXX.log)
PHASE2_LOG=$(mktemp -t wb-join.XXXXXX.log)
P1_PID=""
P2_PID=""
cleanup() {
[ -n "$P2_PID" ] && kill "$P2_PID" 2>/dev/null
[ -n "$P1_PID" ] && kill "$P1_PID" 2>/dev/null
wait 2>/dev/null
}
trap cleanup EXIT INT TERM
echo "=== phase 1: create room ==="
"$CREATOR" > "$PHASE1_LOG" 2>&1 &
P1_PID=$!
waited=0
JOIN_LINK=""
while [ "$waited" -lt "$SETTLE_TIMEOUT" ]; do
JOIN_LINK=$(grep -m1 -oE "wbstream://[A-Za-z0-9-]+" "$PHASE1_LOG" | head -1)
[ -n "$JOIN_LINK" ] && break
if ! kill -0 "$P1_PID" 2>/dev/null; then
echo "FAIL: phase 1 process died" >&2
tail -20 "$PHASE1_LOG" >&2
exit 1
fi
sleep 1
waited=$((waited + 1))
done
if [ -z "$JOIN_LINK" ]; then
echo "FAIL: phase 1 did not print join_link within ${SETTLE_TIMEOUT}s" >&2
tail -20 "$PHASE1_LOG" >&2
exit 1
fi
echo "phase 1 join_link: $JOIN_LINK"
sleep 3
echo ""
echo "=== phase 2: join existing room via -room ==="
"$CREATOR" -room "$JOIN_LINK" > "$PHASE2_LOG" 2>&1 &
P2_PID=$!
waited=0
while [ "$waited" -lt "$SETTLE_TIMEOUT" ]; do
if grep -q "\[lk\] join: room=" "$PHASE2_LOG"; then
break
fi
if grep -qE "Failed to|register guest|create room" "$PHASE2_LOG" | grep -qiE "error|failed"; then
break
fi
if ! kill -0 "$P2_PID" 2>/dev/null; then
break
fi
sleep 1
waited=$((waited + 1))
done
echo ""
echo "--- phase 2 log tail ---"
tail -25 "$PHASE2_LOG"
phase2_room=$(grep -m1 -oE "room=[a-f0-9-]+" "$PHASE2_LOG" | head -1 | cut -d= -f2)
expected_room=$(echo "$JOIN_LINK" | sed 's|wbstream://||')
if [ "$phase2_room" = "$expected_room" ]; then
echo ""
echo "PASS: phase 2 joined room $phase2_room"
exit 0
fi
echo ""
echo "FAIL: phase 2 did not join the expected room (got '$phase2_room', wanted '$expected_room')" >&2
exit 1
-135
View File
@@ -1,135 +0,0 @@
#!/bin/sh
# End-to-end smoke test: spawn a wbstream creator + joiner pair, route curl
# through the joiner's SOCKS5 and verify the response arrives.
#
# Usage:
# ./test-wbstream.sh [video|dc] # default: video
set -u
ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
CREATOR="$ROOT/headless/wbstream/headless-wbstream-creator"
JOINER="$ROOT/headless/wbstream-joiner/headless-wbstream-joiner"
COOKIES="${WBSTREAM_COOKIES:-$ROOT/cookies-wbstream.json}"
SOCKS_PORT=11080
TARGET_URL="https://api.ipify.org"
PROBE_TIMEOUT=15
SETTLE_TIMEOUT=20
mode_arg="${1:-video}"
case "$mode_arg" in
video|dc) ;;
*)
echo "Unknown mode: $mode_arg (expected video or dc)" >&2
exit 2
;;
esac
CREATOR_LOG=$(mktemp -t wb-c.XXXXXX.log)
JOINER_LOG=$(mktemp -t wb-j.XXXXXX.log)
CREATOR_PID=""
JOINER_PID=""
cleanup() {
[ -n "$JOINER_PID" ] && kill "$JOINER_PID" 2>/dev/null
[ -n "$CREATOR_PID" ] && kill "$CREATOR_PID" 2>/dev/null
wait 2>/dev/null
}
trap cleanup EXIT INT TERM
require_bin() {
if [ ! -x "$1" ]; then
echo "FAIL: missing binary $1" >&2
echo "Run ./build-headless.sh first." >&2
exit 2
fi
}
require_bin "$CREATOR"
require_bin "$JOINER"
if [ ! -f "$COOKIES" ]; then
echo "FAIL: cookies file not found at $COOKIES" >&2
echo "Set WBSTREAM_COOKIES or place cookies-wbstream.json at repo root." >&2
exit 2
fi
echo "=== mode=$mode_arg ==="
"$CREATOR" --cookies "$COOKIES" > "$CREATOR_LOG" 2>&1 &
CREATOR_PID=$!
waited=0
JOIN_LINK=""
while [ "$waited" -lt "$SETTLE_TIMEOUT" ]; do
JOIN_LINK=$(grep -m1 "join_link:" "$CREATOR_LOG" | awk '{print $2}')
[ -n "$JOIN_LINK" ] && break
sleep 1
waited=$((waited + 1))
done
if [ -z "$JOIN_LINK" ]; then
echo "FAIL: creator did not print a join_link within ${SETTLE_TIMEOUT}s" >&2
tail -20 "$CREATOR_LOG" >&2
exit 1
fi
echo "join_link=$JOIN_LINK"
"$JOINER" --room "$JOIN_LINK" --socks-port "$SOCKS_PORT" --tunnel-mode "$mode_arg" \
> "$JOINER_LOG" 2>&1 &
JOINER_PID=$!
waited=0
while [ "$waited" -lt "$SETTLE_TIMEOUT" ]; do
if grep -q "TUNNEL CONNECTED" "$JOINER_LOG"; then
break
fi
sleep 1
waited=$((waited + 1))
done
if ! grep -q "TUNNEL CONNECTED" "$JOINER_LOG"; then
echo "FAIL: joiner did not reach TUNNEL CONNECTED within ${SETTLE_TIMEOUT}s" >&2
tail -20 "$JOINER_LOG" >&2
exit 1
fi
# SOCKS listener starts in a goroutine after TUNNEL CONNECTED prints; poll.
waited=0
while [ "$waited" -lt 10 ]; do
if nc -z 127.0.0.1 "$SOCKS_PORT" 2>/dev/null; then
break
fi
sleep 1
waited=$((waited + 1))
done
if ! nc -z 127.0.0.1 "$SOCKS_PORT" 2>/dev/null; then
echo "FAIL: SOCKS5 port $SOCKS_PORT never opened" >&2
exit 1
fi
response=$(curl --socks5 "127.0.0.1:$SOCKS_PORT" -m "$PROBE_TIMEOUT" -sv "$TARGET_URL" 2>&1)
if ! echo "$response" | grep -q "HTTP/.* 200"; then
echo "FAIL: SOCKS5 request did not return HTTP 200" >&2
echo "--- curl output ---" >&2
echo "$response" >&2
echo "--- joiner log tail ---" >&2
tail -30 "$JOINER_LOG" >&2
echo "--- creator log tail ---" >&2
tail -30 "$CREATOR_LOG" >&2
exit 1
fi
response=$(echo "$response" | tail -1)
echo "remote_ip=$response"
speed=$(curl --socks5 "127.0.0.1:$SOCKS_PORT" -m 30 -s -o /dev/null \
-w "%{speed_download}" \
"https://speed.cloudflare.com/__down?bytes=10485760")
if [ -z "$speed" ] || [ "$speed" = "0" ]; then
echo "FAIL: throughput probe returned 0 B/s" >&2
exit 1
fi
mbps=$(awk -v b="$speed" 'BEGIN { printf "%.2f", b * 8 / 1000000 }')
echo "throughput=${mbps} Mbps"
echo "PASS: mode=$mode_arg"