test: add local 2x2 route topology

This commit is contained in:
2026-07-23 03:14:16 +00:00
parent 10e803eaee
commit a66269cb69
27 changed files with 775 additions and 7 deletions
+19
View File
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
set -euo pipefail
source "$(dirname "$0")/lib.sh"
for ((index=${#E2E_NODES[@]} - 1; index >= 0; index--)); do
compose_node "${E2E_NODES[index]}" down --remove-orphans
done
compose_control down --remove-orphans
label=$(docker network inspect \
-f '{{ index .Labels "archive-control.e2e" }}' \
"$E2E_NETWORK" 2>/dev/null || true)
if [[ "$label" == "true" ]]; then
docker network rm "$E2E_NETWORK" >/dev/null
fi
printf 'E2E containers stopped; bind-mounted runtime state was retained.\n'
+29
View File
@@ -0,0 +1,29 @@
#!/usr/bin/env bash
set -euo pipefail
E2E_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
E2E_NETWORK=archive-control-e2e
E2E_NODES=(cache-1 cache-2 archive-1 archive-2)
if [[ -z "${ARCHIVE_CONTROL_SOURCE:-}" ]]; then
control_candidate="$E2E_ROOT/../../../mogic-bot/mogic-repo"
if [[ -d "$control_candidate" ]]; then
ARCHIVE_CONTROL_SOURCE=$(cd "$control_candidate" && pwd)
else
ARCHIVE_CONTROL_SOURCE=$control_candidate
fi
fi
export ARCHIVE_CONTROL_SOURCE
compose_control() {
docker compose \
-p archive-e2e-control \
-f "$E2E_ROOT/control/compose.yaml" "$@"
}
compose_node() {
local node=$1
shift
docker compose \
-p "archive-e2e-${node}" \
-f "$E2E_ROOT/${node}/compose.yaml" "$@"
}
+10
View File
@@ -0,0 +1,10 @@
#!/usr/bin/env bash
set -euo pipefail
source "$(dirname "$0")/lib.sh"
compose_control logs --no-color --tail=200 || true
for node in "${E2E_NODES[@]}"; do
compose_node "$node" logs --no-color --tail=200 || true
done
+45
View File
@@ -0,0 +1,45 @@
#!/usr/bin/env bash
set -euo pipefail
source "$(dirname "$0")/lib.sh"
umask 077
prepare_secret() {
local path=$1
local value=$2
if [[ ! -f "$path" ]]; then
printf '%s\n' "$value" >"$path"
fi
chmod 600 "$path"
}
mkdir -p \
"$E2E_ROOT/control/runtime/state" \
"$E2E_ROOT/control/runtime/backups" \
"$E2E_ROOT/control/secrets"
prepare_secret \
"$E2E_ROOT/control/secrets/archive_control_token" \
"archive-control-e2e-token"
for node in "${E2E_NODES[@]}"; do
node_root="$E2E_ROOT/$node"
mkdir -p \
"$node_root/secrets" \
"$node_root/runtime/syncthing" \
"$node_root/runtime/sync" \
"$node_root/runtime/qb-config/qBittorrent" \
"$node_root/runtime/qb-data" \
"$node_root/runtime/client-state" \
"$node_root/runtime/client-backups"
prepare_secret \
"$node_root/secrets/archive_control_token" \
"archive-control-e2e-token"
prepare_secret \
"$node_root/secrets/syncthing_api_key" \
"archive-control-e2e-${node}-syncthing-key"
prepare_secret "$node_root/secrets/qb_password" "adminadmin"
qb_config="$node_root/runtime/qb-config/qBittorrent/qBittorrent.conf"
if [[ ! -f "$qb_config" ]]; then
cp "$E2E_ROOT/common/qBittorrent.conf" "$qb_config"
fi
done
+23
View File
@@ -0,0 +1,23 @@
#!/usr/bin/env bash
set -euo pipefail
source "$(dirname "$0")/lib.sh"
"$E2E_ROOT/scripts/prepare.sh"
if ! docker network inspect "$E2E_NETWORK" >/dev/null 2>&1; then
docker network create \
--label archive-control.e2e=true \
"$E2E_NETWORK" >/dev/null
fi
if [[ ! -f "$ARCHIVE_CONTROL_SOURCE/Dockerfile.archive-control" ]]; then
printf 'control source is missing Dockerfile.archive-control: %s\n' \
"$ARCHIVE_CONTROL_SOURCE" >&2
exit 2
fi
compose_control up -d --build control
for node in "${E2E_NODES[@]}"; do
compose_node "$node" up -d --build
done
"$E2E_ROOT/scripts/wait-routes.sh"
+29
View File
@@ -0,0 +1,29 @@
#!/usr/bin/env bash
set -euo pipefail
source "$(dirname "$0")/lib.sh"
timeout_seconds=${E2E_WAIT_SECONDS:-360}
deadline=$((SECONDS + timeout_seconds))
while (( SECONDS < deadline )); do
payload=$(compose_control run --rm --no-deps \
--entrypoint /bin/sh curl -c \
'curl --max-time 5 -fsS http://127.0.0.1:18081/test/v1/clients; printf "\n"; curl --max-time 5 -fsS http://127.0.0.1:18081/test/v1/routes' \
2>/dev/null || true)
clients=${payload%%$'\n'*}
routes=${payload#*$'\n'}
client_count=$(grep -o '"client_id"' <<<"$clients" | wc -l || true)
ready_count=$(grep -o '"state":"ready"' <<<"$routes" | wc -l || true)
if [[ "$client_count" -eq 4 && "$ready_count" -eq 4 ]]; then
printf '2x2 route mesh ready: clients=%s ready_routes=%s\n' \
"$client_count" "$ready_count"
printf '%s\n' "$routes"
exit 0
fi
sleep 2
done
printf 'timed out waiting for 2x2 route mesh after %ss\n' \
"$timeout_seconds" >&2
"$E2E_ROOT/scripts/logs.sh" >&2
exit 1