forked from mtusi2026/mtusi2026lab2
82 lines
2.9 KiB
Bash
Executable File
82 lines
2.9 KiB
Bash
Executable File
#!/bin/sh
|
|
set -eu
|
|
cd "$(dirname "$0")/.."
|
|
|
|
PYTHON="${PYTHON:-python3}"
|
|
BASE_URL="${BASE_URL:-http://localhost:8080}"
|
|
OUT=evidence
|
|
|
|
compose() {
|
|
docker compose --env-file .env "$@"
|
|
}
|
|
|
|
wait_ready() {
|
|
for _ in $(seq 1 90); do
|
|
curl -sf "$BASE_URL/health/ready" >/dev/null && return 0
|
|
sleep 1
|
|
done
|
|
echo "API $BASE_URL не готов" >&2
|
|
exit 1
|
|
}
|
|
|
|
{
|
|
echo "date: $(date -u +%Y-%m-%dT%H:%M:%SZ)"
|
|
echo "commit: $(git rev-parse --short HEAD)$(git diff --quiet HEAD -- app migrations tests scripts compose.yaml Dockerfile infra || echo ' (+ uncommitted changes)')"
|
|
echo "branch: $(git rev-parse --abbrev-ref HEAD)"
|
|
echo "cpu: $(lscpu | sed -n 's/^Model name:[[:space:]]*//p') ($(nproc) threads)"
|
|
echo "memory: $(free -h | awk '/^Mem:/ {print $2}')"
|
|
echo "kernel: $(uname -r)"
|
|
echo "docker: $(docker version --format '{{.Server.Version}}')"
|
|
echo "compose: $(docker compose version --short)"
|
|
echo "python: $($PYTHON --version 2>&1)"
|
|
echo "stand: $BASE_URL (compose project ${COMPOSE_PROJECT_NAME:-default})"
|
|
echo
|
|
compose ps --format 'table {{.Service}}\t{{.Image}}\t{{.Status}}'
|
|
} > "$OUT/00-environment.txt"
|
|
|
|
DOCKER_TESTS=1 "$PYTHON" -m pytest tests -v -p no:cacheprovider 2>&1 \
|
|
| grep -E "PASSED|FAILED|SKIPPED|ERROR|passed|failed" > "$OUT/01-pytest.txt"
|
|
|
|
"$PYTHON" tests/smoke.py --base-url "$BASE_URL" > "$OUT/02-smoke.txt" 2>&1
|
|
|
|
{
|
|
echo "== before"
|
|
compose ps --format 'table {{.Service}}\t{{.Status}}'
|
|
echo
|
|
"$PYTHON" tests/resilience.py --mode persistence \
|
|
--action-script scripts/restart.sh --base-url "$BASE_URL" 2>&1
|
|
echo
|
|
echo "== after (Up N seconds = container was restarted by scripts/restart.sh)"
|
|
compose ps --format 'table {{.Service}}\t{{.Status}}'
|
|
} > "$OUT/03-persistence.txt"
|
|
|
|
DB_HOST=localhost DB_PORT="${DB_HOST_PORT:-5432}" PYTHONPATH=. \
|
|
"$PYTHON" scripts/explain_history.py > "$OUT/04-explain-history.txt"
|
|
|
|
BASE_URL="$BASE_URL" scripts/failure_demo.sh > "$OUT/05-failures.txt" 2>&1
|
|
|
|
{
|
|
for key in appendonly appendfsync maxmemory maxmemory-policy dir; do
|
|
compose exec -T redis redis-cli CONFIG GET "$key" | paste -sd' '
|
|
done
|
|
echo
|
|
compose exec -T redis redis-cli INFO persistence \
|
|
| grep -E "^(aof_enabled|aof_last_write_status|aof_last_bgrewrite_status|loading):"
|
|
} > "$OUT/06-redis-config.txt"
|
|
|
|
"$PYTHON" tests/load.py --base-url "$BASE_URL" --duration 20 --concurrency 8 \
|
|
--output "$OUT/07-load.json" > /dev/null &
|
|
LOAD_PID=$!
|
|
sleep 10
|
|
docker stats --no-stream --format 'table {{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}' \
|
|
$(compose ps -q) > "$OUT/07-load-resources.txt"
|
|
wait "$LOAD_PID"
|
|
|
|
SESSION_TTL_SECONDS=3 compose up -d api >/dev/null 2>&1
|
|
wait_ready
|
|
BASE_URL="$BASE_URL" TTL=3 scripts/expiry_demo.sh > "$OUT/08-expiry.txt" 2>&1
|
|
compose up -d api >/dev/null 2>&1
|
|
wait_ready
|
|
|
|
echo "evidence written to $OUT/"
|