Files
ukmesh/scripts/full-dev/replay/test-bridge-session.sh

48 lines
1.9 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
# Exercise the exact bridge configuration against an isolated sample broker.
here=$(cd "$(dirname "$0")" && pwd)
image=ukmesh-sample-mosquitto:2.1.2-session-accounting-v1
work=$(mktemp -d)
id="ukmesh-bridge-test-${RANDOM}-$$"
network="$id-net"
source="$id-src"
target="$id-dst"
cleanup() {
docker rm -fv "$source" "$target" >/dev/null 2>&1 || true
docker network rm "$network" >/dev/null 2>&1 || true
rm -rf "$work"
}
trap cleanup EXIT
chmod 755 "$work"
cat > "$work/target.conf" <<'CONF'
listener 1883
allow_anonymous true
sys_interval 1
CONF
chmod 644 "$work/target.conf"
docker network create --internal "$network" >/dev/null
docker run -d --name "$target" --network "$network" --network-alias ukmesh-sample-mqtt \
-v "$work/target.conf:/mosquitto/config/test.conf:ro" "$image" mosquitto -c /mosquitto/config/test.conf >/dev/null
docker run -d --name "$source" --network "$network" \
-v "$here/mosquitto.conf:/mosquitto/config/replay.conf:ro" "$image" mosquitto -c /mosquitto/config/replay.conf >/dev/null
await_value() {
local container=$1 topic=$2 expected=$3
for ((attempt=0;attempt<30;attempt++)); do
if [[ $(docker exec "$container" mosquitto_sub -t "$topic" -C 1 -W 2 2>/dev/null) == "$expected" ]]; then return; fi
sleep 1
done
return 1
}
await_value "$source" local/archive/bridge 1
docker stop "$target" >/dev/null
await_value "$source" local/archive/bridge 0
docker exec "$source" mosquitto_pub -t meshcore/fixture/test/packets -m retained-fixture -q 1 -r
# Recover a queued outbound publication after restarting both brokers.
docker stop "$source" >/dev/null
docker start "$target" "$source" >/dev/null
await_value "$target" meshcore/fixture/test/packets retained-fixture
docker stop "$source" >/dev/null
await_value "$target" '$SYS/broker/clients/disconnected' 0
echo 'Outbound bridge resumed queued work and left no disconnected remote session'