From aed5566956c082c839a1aadbac531995aa15cfd0 Mon Sep 17 00:00:00 2001 From: Audric Date: Wed, 15 Apr 2026 13:40:44 +0200 Subject: [PATCH] Split run_redis_tests.sh into up/test/down subcommands MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Default 'all' runs the full cycle (CI-friendly). Developers can use 'up' once, 'test' repeatedly as they iterate, 'down' when finished. Dramatically cuts per-iteration overhead — no rebuild or healthcheck wait between test runs. --- tests/run_redis_tests.sh | 61 +++++++++++++++++++++++++++++++++------- 1 file changed, 51 insertions(+), 10 deletions(-) diff --git a/tests/run_redis_tests.sh b/tests/run_redis_tests.sh index d9e1d8f..6dcdadb 100755 --- a/tests/run_redis_tests.sh +++ b/tests/run_redis_tests.sh @@ -2,17 +2,58 @@ set -euo pipefail cd "$(dirname "$0")" -cleanup() { - echo "=== Tearing down Redis test environment ===" - docker compose -f docker-compose.redis.yml down -v --remove-orphans 2>/dev/null +COMPOSE="docker compose -f docker-compose.redis.yml" + +cmd=${1:-all} + +usage() { + cat <<'USAGE' +Usage: run_redis_tests.sh [up|test|down|all|help] + + up Generate configs, build, and start the Redis test stack (leave running). + test Run python3 test_redis.py against the already-running stack. + down Tear the stack down (docker compose down -v --remove-orphans). + all Full cycle: up -> test -> down. This is the default and CI-friendly. + help This message. + +Typical dev loop: + bash run_redis_tests.sh up # once + bash run_redis_tests.sh test # many times as you edit test_redis.py + bash run_redis_tests.sh down # when finished +USAGE } -trap cleanup EXIT -echo "=== Generating Redis-test configs from topology_redis.py ===" -python3 generate_redis_configs.py +is_stack_up() { + $COMPOSE ps --status=running --services 2>/dev/null | grep -q '^reflector-r1$' +} -echo "=== Building and starting Redis test stack ===" -docker compose -f docker-compose.redis.yml up -d --build --wait +cmd_up() { + echo "=== Generating Redis-test configs from topology_redis.py ===" + python3 generate_redis_configs.py + echo "=== Building and starting Redis test stack ===" + $COMPOSE up -d --build --wait + echo "=== Stack is up. Run 'bash run_redis_tests.sh test' to run tests." +} -echo "=== Running Redis integration tests ===" -python3 test_redis.py +cmd_test() { + if ! is_stack_up; then + echo "Stack is not running. Run 'bash run_redis_tests.sh up' first." >&2 + exit 1 + fi + echo "=== Running Redis integration tests ===" + python3 test_redis.py +} + +cmd_down() { + echo "=== Tearing down Redis test environment ===" + $COMPOSE down -v --remove-orphans +} + +case "$cmd" in + up) cmd_up ;; + test) cmd_test ;; + down) cmd_down ;; + all) cmd_up; cmd_test; cmd_down ;; + help|-h|--help) usage ;; + *) echo "Unknown command: $cmd" >&2; usage >&2; exit 1 ;; +esac