Files
mtusi2026lab2/student-tests/expiry.sh
T

36 lines
1.2 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/sh
set -eu
cd "$(dirname "$0")/.."
NAME=mtusi-lab2-api-shortttl
PORT=${PORT:-8081}
NETWORK=$(docker compose --env-file .env ps --format '{{.Name}}' api | head -1 | xargs -I{} docker inspect {} --format '{{range $k,$v := .NetworkSettings.Networks}}{{$k}}{{end}}')
cleanup() {
docker rm -f "$NAME" >/dev/null 2>&1 || true
}
trap cleanup EXIT
cleanup
echo "Поднимаю отдельный API с SESSION_TTL_SECONDS=2 на порту $PORT (сеть $NETWORK)"
docker run -d --name "$NAME" --network "$NETWORK" \
-p 127.0.0.1:"$PORT":8080 \
-v "$PWD/secrets/database_url:/run/secrets/database_url:ro" \
-v "$PWD/secrets/cache_url:/run/secrets/cache_url:ro" \
-e DATABASE_URL_FILE=/run/secrets/database_url \
-e CACHE_URL_FILE=/run/secrets/cache_url \
-e SESSION_TTL_SECONDS=2 \
-e SESSION_CACHE_TTL_SECONDS=2 \
-e SESSION_SWEEP_SECONDS=5 \
mtusi-messenger:lab2 >/dev/null
i=0
while [ "$i" -lt 60 ]; do
if curl -fsS "http://localhost:$PORT/health/ready" >/dev/null 2>&1; then break; fi
i=$((i + 1))
sleep 1
done
curl -fsS "http://localhost:$PORT/health/ready" >/dev/null
python3 student-tests/test_expiry.py --base-url "http://localhost:$PORT"