Path: redb-route/tests/docker/run-fault-suite.sh Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route Page: https://redbase.app/src/dev-2026-12-06/redb-route/tests/docker/run-fault-suite.sh ---- #!/usr/bin/env bash # Runs the broker-fault tests of one connector suite on a docker host: the tests restart or pause the broker's container # (tests/Shared/Conformance/BrokerFault.cs), so they are not run by the release gate. # # bash redb.Route/tests/docker/run-fault-suite.sh --image --broker ibmmq \ # --project redb.Route.Tests.IbmMq --filter IbmMqReconnectTests [--framework net10.0] [--wait 300] # # The shape of the run is fixed, because each part of it was paid for: # 1. The suite is built in its own short-lived container, and the tests run in a second one with # --no-build. Build and test in one container left MSBuild and compiler servers behind that kept the test # container alive after the last test. # 2. The broker runs with host networking: behind docker's published-port proxy a client connect made while the # broker starts can hang for minutes. # 3. The broker is ready when its own health command passes (or, where running its CLI early breaks it, when it logs # that it started), not when a client connects. # 4. After the summary the test host must exit within 60 s. If it does not, its processes and their thread names are # printed and the run fails: a host that stays is a defect, not a slow machine. # # Run it from a copy of the repository on the docker host (git archive, nothing of the private key material). The # sources are mounted into the containers; bin and obj are written into the copy. Everything the run starts is # removed when it ends, the work folder with the NuGet cache included. # # --image SDK image that builds the solution and runs --framework (the solution targets net10.0 and net11.0, so # the image needs SDK 11 and the .NET 10 runtime for a net10.0 run). # --broker the broker to start: ibmmq, rabbitmq, artemis (AMQP 1.0), mosquitto (MQTT), kafka (one KRaft node) or # servicebus (the Service Bus emulator with its own SQL container). # --project test project under redb.Route/tests. # --filter dotnet test filter; FullyQualifiedName~ when it has no operator. # --framework target framework of the test run, net10.0 by default. # --wait seconds a test waits for the broker or the route (REDB_TEST_BROKER_WAIT_SECONDS); 120 when not given. # --work folder for the NuGet cache, the home of the run and the logs; ${TMPDIR:-/tmp}/redb-route-fault by default. # --prefix prefix of the container names, route-fault by default. # --memory memory cap of the build and test containers, 4g by default. # --build-minutes the build is stopped and the run fails after this many minutes, 15 by default. # --test-minutes the tests are stopped and the run fails after this many minutes, 20 by default. # # One run per host: a second start is refused while a lock (flock on /tmp/redb-route-fault.lock) is held or a container # labelled org.redbase.route-fault exists; foreign containers are only read, never touched. On any exit, the timeouts # included, the run removes its containers by exact name and its work folder (the summary and the end of the test # log are printed before). set -euo pipefail IMAGE=""; BROKER=""; PROJECT=""; FILTER=""; FRAMEWORK=net10.0; WAIT=""; PREFIX=route-fault; MEMORY=4g; BUILD_MINUTES=15; TEST_MINUTES=20 WORK="${TMPDIR:-/tmp}/redb-route-fault" while [ $# -gt 0 ]; do case "$1" in --image) IMAGE=$2; shift 2 ;; --broker) BROKER=$2; shift 2 ;; --project) PROJECT=$2; shift 2 ;; --filter) FILTER=$2; shift 2 ;; --framework) FRAMEWORK=$2; shift 2 ;; --wait) WAIT=$2; shift 2 ;; --work) WORK=$2; shift 2 ;; --prefix) PREFIX=$2; shift 2 ;; --memory) MEMORY=$2; shift 2 ;; --build-minutes) BUILD_MINUTES=$2; shift 2 ;; --test-minutes) TEST_MINUTES=$2; shift 2 ;; *) echo "unknown argument: $1" >&2; exit 64 ;; esac done [ -n "$IMAGE" ] && [ -n "$BROKER" ] && [ -n "$PROJECT" ] || { echo "--image, --broker and --project are required" >&2; exit 64; } case "$FILTER" in *[=~!]*) ;; "") ;; *) FILTER="FullyQualifiedName~$FILTER" ;; esac # The repository root: three levels above this file (redb.Route/tests/docker). ROOT=$(cd "$(dirname "$0")/../../.." && pwd) SUITE=$ROOT/redb.Route/tests/$PROJECT [ -d "$SUITE" ] || { echo "no test project $SUITE" >&2; exit 64; } # ---- brokers: image, start arguments, readiness (health command or log line), the variables that name the container # for the tests --------------------------------------------------------------------------------------------------------- MQ_NAME=$PREFIX-$BROKER BROKER_COMMAND=() # A container the broker needs beside it (the emulator's SQL), started first and never broken by the tests. SIDE_NAME=""; SIDE_IMAGE=""; SIDE_ARGS=(); SIDE_READY_LOG="" case "$BROKER" in ibmmq) # Same image as docker-compose.tests.yml; a new tag is a deliberate bump in both places. BROKER_IMAGE=icr.io/ibm-messaging/mq:9.4.5.0-r2 BROKER_ARGS=(--memory 2g -e LICENSE=accept -e MQ_QMGR_NAME=QM1 -e MQ_APP_PASSWORD=admin -e MQ_ADMIN_PASSWORD=admin -e MQ_DEV=true -v "$ROOT/redb.Route/tests/docker/ibmmq/redb-tests.mqsc:/etc/mqm/90-redb-tests.mqsc:ro") BROKER_HEALTH=(chkmqhealthy) BROKER_READY_LOG="" BROKER_VARIABLES=(REDB_TEST_IBMMQ_CONTAINER) ;; rabbitmq) # Same image and data folder as docker-compose.tests.yml. Ready by its log line, not by its CLI: a CLI run as root # before the broker writes its Erlang cookie writes it first, the broker cannot read it and stops with eacces. # REDB_RABBITMQ_CONTAINER is the name RabbitMQBlockedBrokerTests runs rabbitmqctl in. BROKER_IMAGE=rabbitmq:4.3-management-alpine BROKER_ARGS=(--memory 1g -e RABBITMQ_DEFAULT_USER=admin -e RABBITMQ_DEFAULT_PASS=admin --tmpfs /var/lib/rabbitmq:mode=1777) BROKER_HEALTH=() BROKER_READY_LOG="Server startup complete" BROKER_VARIABLES=(REDB_TEST_RABBITMQ_CONTAINER REDB_RABBITMQ_CONTAINER) ;; artemis) # Same image as docker-compose.tests.yml. With host networking the AMQP acceptor would take 5672 (RabbitMQ's port # in the compose file); --port-offset 1 moves every acceptor by one, so AMQP is at 5673 as the tests expect. BROKER_IMAGE=apache/activemq-artemis:latest-alpine BROKER_ARGS=(--memory 1g -e ARTEMIS_USER=admin -e ARTEMIS_PASSWORD=admin -e ARTEMIS_MIN_MEMORY=512M -e ARTEMIS_MAX_MEMORY=768M -e "EXTRA_ARGS=--http-host 0.0.0.0 --relax-jolokia --port-offset 1") BROKER_HEALTH=() BROKER_READY_LOG="AMQ221007: Server is now active" BROKER_VARIABLES=(REDB_TEST_AMQP_CONTAINER) ;; mosquitto) # Same image and settings as docker-compose.tests.yml (anonymous, no persistence); with host networking the # listener itself takes 11883, the port the tests expect. BROKER_IMAGE=eclipse-mosquitto:2 BROKER_ARGS=(--memory 256m) BROKER_COMMAND=(sh -c "printf 'listener 11883\nallow_anonymous true\npersistence false\n' > /mosquitto/config/mosquitto.conf && exec /usr/sbin/mosquitto -c /mosquitto/config/mosquitto.conf") BROKER_HEALTH=(mosquitto_sub -h localhost -p 11883 -t '$SYS/broker/uptime' -C 1 -W 3) BROKER_READY_LOG="" BROKER_VARIABLES=(REDB_TEST_MQTT_CONTAINER) ;; kafka) # The image of docker-compose.tests.yml, but one node (controller and broker): stopping one node of the compose # file's three tests a leader change, not a lost connection. Port 39092 (39093 for the controller), away from the # compose file's ports; the data stays in the container, so topics and offsets outlive a stop and a start. BROKER_IMAGE=apache/kafka:3.7.0 BROKER_ARGS=(--memory 1g -e KAFKA_NODE_ID=1 -e KAFKA_PROCESS_ROLES=broker,controller -e KAFKA_LISTENERS=PLAINTEXT://:39092,CONTROLLER://:39093 -e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://localhost:39092 -e KAFKA_CONTROLLER_LISTENER_NAMES=CONTROLLER -e KAFKA_LISTENER_SECURITY_PROTOCOL_MAP=CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT -e KAFKA_CONTROLLER_QUORUM_VOTERS=1@localhost:39093 -e KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=1 -e KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR=1 -e KAFKA_TRANSACTION_STATE_LOG_MIN_ISR=1 -e KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS=0 -e KAFKA_NUM_PARTITIONS=1 -e KAFKA_HEAP_OPTS=-Xmx512m) BROKER_HEALTH=(/opt/kafka/bin/kafka-broker-api-versions.sh --bootstrap-server localhost:39092) BROKER_READY_LOG="" BROKER_VARIABLES=(REDB_TEST_KAFKA_CONTAINER) ;; servicebus) # The emulator keeps its entities and messages in SQL: its own SQL Edge container beside it, at 14330 (a host may # run its SQL Server on 1433). The entities are those of servicebus/Config.json; the emulator creates none on # request. AMQP at 5672, its HTTP port moved to 15300. Its image has no shell: ready by its log line. SIDE_NAME=$PREFIX-servicebus-sql SIDE_IMAGE=mcr.microsoft.com/azure-sql-edge:2.0.0 SIDE_ARGS=(--memory 2g -e ACCEPT_EULA=Y -e MSSQL_SA_PASSWORD=Fault-Run-Only-1 -e MSSQL_TCP_PORT=14330) SIDE_READY_LOG="SQL Server is now ready for client connections" BROKER_IMAGE=mcr.microsoft.com/azure-messaging/servicebus-emulator:2.0.1 BROKER_ARGS=(--memory 1g -e ACCEPT_EULA=Y -e SQL_SERVER=localhost:14330 -e MSSQL_SA_PASSWORD=Fault-Run-Only-1 -e EMULATOR_HTTP_PORT=15300 -v "$ROOT/redb.Route/tests/docker/servicebus/Config.json:/ServiceBus_Emulator/ConfigFiles/Config.json:ro") BROKER_HEALTH=() BROKER_READY_LOG="Emulator Service is Successfully Up!" BROKER_VARIABLES=(REDB_TEST_ASB_CONTAINER) ;; *) echo "unknown broker: $BROKER (known: ibmmq, rabbitmq, artemis, mosquitto, kafka, servicebus)" >&2; exit 64 ;; esac TESTS=$PREFIX-tests BUILD=$PREFIX-build LABEL=org.redbase.route-fault # ---- one run per host ------------------------------------------------------------------------------------------------ exec 9>/tmp/redb-route-fault.lock flock -n 9 || { echo "another fault run holds /tmp/redb-route-fault.lock on this host; not started" >&2; exit 75; } others=$(docker ps -a --filter "label=$LABEL" --format "{{.Names}}") [ -z "$others" ] || { echo "containers of another fault run exist: $others; not started" >&2; exit 75; } [ ! -e "$WORK" ] || { echo "$WORK exists (another run, or one that was killed); not started" >&2; exit 75; } mkdir -p "$WORK/nuget" "$WORK/home" LOG=$WORK/$PROJECT.tests.log FOLLOW="" remove_containers() { docker rm -f "$BUILD" "$MQ_NAME" "$TESTS" ${SIDE_NAME:+"$SIDE_NAME"} >/dev/null 2>&1 || true; } cleanup() { remove_containers [ -z "$FOLLOW" ] || wait "$FOLLOW" 2>/dev/null || true # The run wrote as the caller (-u), so the folder is the caller's to remove. rm -rf "$WORK" } trap cleanup EXIT DOCKER_CLI=$(command -v docker) SOCKET_GID=$(stat -c %g /var/run/docker.sock) COMMON=(--label "$LABEL" --network host --memory "$MEMORY" -u "$(id -u):$(id -g)" --group-add "$SOCKET_GID" -v /var/run/docker.sock:/var/run/docker.sock -v "$DOCKER_CLI:/usr/bin/docker:ro" -v "$ROOT:/src" -v "$WORK/nuget:/nuget" -v "$WORK/home:/home/run" -e NUGET_PACKAGES=/nuget -e HOME=/home/run -e DOTNET_CLI_HOME=/home/run -e DOTNET_NOLOGO=1 -e REDB_TEST_BROKER_FAULTS=1 -w "/src/redb.Route/tests/$PROJECT") for variable in "${BROKER_VARIABLES[@]}"; do COMMON+=(-e "$variable=$MQ_NAME"); done [ -n "$WAIT" ] && COMMON+=(-e "REDB_TEST_BROKER_WAIT_SECONDS=$WAIT") stamp() { echo "== $* $(date -u +%T)"; } stamp "build $PROJECT ($FRAMEWORK) in its own container" # A build that hangs (a restore that never ends was seen) is stopped by name and fails the run, so it never runs into # the time of whoever shares the host. The build in the SDK test image hangs now and then (MSBuild idle after a finished # restore, with and without --disable-build-servers; cause not found): this limit is the guard. # RedbBrokerFaultRun builds the classes that need a fault stand (the Kafka and Service Bus conformance sets); the release # gate builds without them. docker run -d --name "$BUILD" "${COMMON[@]}" "$IMAGE" \ dotnet build -f "$FRAMEWORK" -p:RedbBrokerFaultRun=true -v q -clp:ErrorsOnly >/dev/null build_code=$(timeout "${BUILD_MINUTES}m" docker wait "$BUILD" || echo timeout) docker logs --tail 40 "$BUILD" 2>&1 | grep -v "warning " || true if [ "$build_code" = timeout ]; then stamp "BUILD DID NOT FINISH within $BUILD_MINUTES min; processes, then the NuGet cache size" docker top "$BUILD" -eo pid,etime,args 2>/dev/null | cut -c1-200 || true echo "packages: $(ls "$WORK/nuget" | wc -l), $(du -sh "$WORK/nuget" | cut -f1)" exit 3 fi docker rm -f "$BUILD" >/dev/null 2>&1 || true [ "$build_code" = 0 ] || { stamp "build failed, code $build_code"; exit 1; } if [ -n "$SIDE_NAME" ]; then stamp "start $SIDE_NAME" docker run -d --name "$SIDE_NAME" --label "$LABEL" --network host "${SIDE_ARGS[@]}" "$SIDE_IMAGE" >/dev/null ready=no for _ in $(seq 1 100); do if docker logs "$SIDE_NAME" 2>&1 | grep -qF "$SIDE_READY_LOG"; then ready=yes; break; fi sleep 3 done [ "$ready" = yes ] || { echo "$SIDE_NAME is not ready after 300 s"; docker logs --tail 40 "$SIDE_NAME"; exit 1; } fi stamp "start $BROKER as $MQ_NAME" docker run -d --name "$MQ_NAME" --label "$LABEL" --network host "${BROKER_ARGS[@]}" "$BROKER_IMAGE" "${BROKER_COMMAND[@]}" >/dev/null ready=no for _ in $(seq 1 200); do if [ -n "$BROKER_READY_LOG" ]; then if docker logs "$MQ_NAME" 2>&1 | grep -qF "$BROKER_READY_LOG"; then ready=yes; break; fi elif docker exec "$MQ_NAME" "${BROKER_HEALTH[@]}" >/dev/null 2>&1; then ready=yes; break; fi sleep 3 done [ "$ready" = yes ] || { echo "$BROKER is not ready after 600 s"; docker logs --tail 40 "$MQ_NAME"; exit 1; } stamp "$BROKER ready" stamp "tests (--no-build)" TEST_ARGS=(dotnet test -f "$FRAMEWORK" --no-build --logger "console;verbosity=normal") [ -n "$FILTER" ] && TEST_ARGS+=(--filter "$FILTER") docker run -d --name "$TESTS" "${COMMON[@]}" "$IMAGE" "${TEST_ARGS[@]}" >/dev/null docker logs -f "$TESTS" > "$LOG" 2>&1 & FOLLOW=$! running() { [ "$(docker inspect -f '{{.State.Running}}' "$TESTS" 2>/dev/null)" = true ]; } deadline=$(( $(date +%s) + TEST_MINUTES * 60 )) while running && ! grep -q "Total tests:" "$LOG" && [ "$(date +%s)" -lt "$deadline" ]; do sleep 2; done if running && ! grep -q "Total tests:" "$LOG"; then stamp "TESTS DID NOT FINISH within $TEST_MINUTES min; processes and thread names" docker exec "$TESTS" sh -c 'for p in /proc/[0-9]*; do [ -r $p/cmdline ] || continue; echo "-- pid ${p#/proc/}: $(tr "\0" " " < $p/cmdline | cut -c1-200)"; for t in $p/task/*; do cat $t/comm; done | sort | uniq -c; done' || true tail -n 60 "$LOG" exit 4 fi for _ in $(seq 1 30); do running || break; sleep 2; done if running; then stamp "TEST HOST DID NOT EXIT within 60 s after the summary; processes and thread names" docker exec "$TESTS" sh -c 'for p in /proc/[0-9]*; do [ -r $p/cmdline ] || continue; echo "-- pid ${p#/proc/}: $(tr "\0" " " < $p/cmdline | cut -c1-200)"; for t in $p/task/*; do cat $t/comm; done | sort | uniq -c; done' || true code=2 else code=$(docker inspect -f '{{.State.ExitCode}}' "$TESTS") stamp "test host exited, code $code" fi if [ "$code" != 0 ]; then # The broker the tests stopped and started may be what failed: its state and the end of its log, before it is removed. stamp "broker $MQ_NAME: $(docker inspect -f '{{.State.Status}} exit {{.State.ExitCode}} oom {{.State.OOMKilled}}' "$MQ_NAME" 2>&1)" docker logs --tail 40 "$MQ_NAME" 2>&1 | cut -c1-300 || true fi remove_containers # ends the log follower too wait "$FOLLOW" 2>/dev/null || true FOLLOW="" if [ "$code" != 0 ]; then tail -n 60 "$LOG" stamp "error messages of the failed tests" grep -A12 "Error Message:" "$LOG" | head -n 600 || true fi grep -E "^\s+(Passed|Failed|Skipped) |^Total tests:|^\s+(Passed|Failed|Skipped):|Total time:" "$LOG" || true exit "$code"