forked from mtusi2026/mtusi2026lab2
40 lines
1006 B
Bash
Executable File
40 lines
1006 B
Bash
Executable File
#!/bin/sh
|
|
set -eu
|
|
cd "$(dirname "$0")/.."
|
|
|
|
COMPOSE="docker compose --env-file .env"
|
|
|
|
wait_ready() {
|
|
i=0
|
|
while [ "$i" -lt 60 ]; do
|
|
if curl -fsS http://localhost:8080/health/ready >/dev/null 2>&1; then return 0; fi
|
|
i=$((i + 1))
|
|
sleep 1
|
|
done
|
|
echo "API не стал ready" >&2
|
|
return 1
|
|
}
|
|
|
|
restore() {
|
|
$COMPOSE start valkey postgres >/dev/null 2>&1 || true
|
|
}
|
|
trap restore EXIT
|
|
|
|
echo "=== 1. Останавливаю кэш сессий (valkey) ==="
|
|
$COMPOSE stop valkey
|
|
$COMPOSE ps --format '{{.Service}} {{.Status}}'
|
|
python3 student-tests/test_without_cache.py --base-url http://localhost:8080
|
|
$COMPOSE start valkey
|
|
wait_ready
|
|
|
|
echo
|
|
echo "=== 2. Останавливаю PostgreSQL ==="
|
|
$COMPOSE stop postgres
|
|
$COMPOSE ps --format '{{.Service}} {{.Status}}'
|
|
python3 student-tests/test_without_db.py --base-url http://localhost:8080
|
|
$COMPOSE start postgres
|
|
wait_ready
|
|
echo
|
|
echo "=== 3. Состояние восстановлено ==="
|
|
$COMPOSE ps --format '{{.Service}} {{.Status}}'
|