Files
2026-11-07 00:02:31 +03:00

40 lines
1.2 KiB
Bash
Executable File

#!/usr/bin/env bash
# Собственные автотесты: auth/TTL/logout/гонки/откат/пагинация/отказы Valkey и БД. Одна команда: make test-own
set -euo pipefail
cd "$(dirname "$0")/.."
export BASE_URL="${BASE_URL:-http://localhost:8080}"
PY="${PYTHON:-python3}"
$PY -c "import pytest, httpx" 2>/dev/null || { echo "pip install pytest httpx"; exit 1; }
wait_ready() {
for _ in $(seq 1 90); do curl -fs "$BASE_URL/health/ready" >/dev/null && return 0; sleep 1; done
echo "API not ready"; return 1
}
wait_healthy() {
for _ in $(seq 1 60); do
s=$(docker inspect -f '{{.State.Health.Status}}' "$1" 2>/dev/null || echo none)
[ "$s" = healthy ] && return 0
sleep 1
done
echo "$1 is not healthy" >&2
return 1
}
docker compose up -d --build
wait_ready
$PY -m pytest tests_own -m "not ttl" -v
wait_healthy lab2_postgres
wait_healthy lab2_valkey
# Короткий TTL только для проверки истечения сессии
SESSION_TTL_SECONDS=2 docker compose up -d --force-recreate app
wait_ready
$PY -m pytest tests_own -m ttl -v
# Вернуть TTL по умолчанию
docker compose up -d --force-recreate app
wait_ready
echo "OK"