forked from mtusi2026/mtusi2026lab2
92 lines
3.4 KiB
Makefile
92 lines
3.4 KiB
Makefile
PYTHON ?= python3
|
||
# 127.0.0.1, а не localhost: на части Windows-машин localhost резолвится очень медленно.
|
||
BASE_URL ?= http://127.0.0.1:8080
|
||
# Второй экземпляр API с SESSION_TTL_SECONDS=2 (сервис api-short-ttl, профиль ttl).
|
||
BASE_URL_TTL ?= http://127.0.0.1:8081
|
||
CA_FILE ?=
|
||
ACTION_SCRIPT ?=
|
||
TLS_ARGS = $(if $(CA_FILE),--ca-file "$(CA_FILE)",)
|
||
# Передаём адреса собственным тестам через окружение (работает и в cmd, и в sh).
|
||
export BASE_URL
|
||
export BASE_URL_TTL
|
||
|
||
.PHONY: help check validate test load test-persistence \
|
||
secrets up down ps logs student-test race expiry failure-valkey failure-postgres failure-valkey-pause db-test explain demo cache-stats
|
||
|
||
help:
|
||
@echo "check: offline structure; validate: full OpenAPI (requirements-dev.txt); test: running API; load: synthetic writes"
|
||
@echo "secrets/up/down/ps/logs: stand; student-test, race, expiry, failure-valkey, failure-postgres, failure-valkey-pause, db-test, explain, demo, cache-stats: own checks"
|
||
|
||
check:
|
||
$(PYTHON) scripts/check_contract.py
|
||
|
||
validate:
|
||
$(PYTHON) scripts/validate_openapi.py
|
||
|
||
test:
|
||
$(PYTHON) tests/smoke.py --base-url "$(BASE_URL)" $(TLS_ARGS)
|
||
|
||
load:
|
||
$(PYTHON) tests/load.py --base-url "$(BASE_URL)" $(TLS_ARGS)
|
||
|
||
test-persistence:
|
||
@test -n "$(ACTION_SCRIPT)" || (echo "Set ACTION_SCRIPT to your implemented executable restart hook"; exit 2)
|
||
$(PYTHON) tests/resilience.py --mode persistence --action-script "$(ACTION_SCRIPT)" --base-url "$(BASE_URL)" $(TLS_ARGS)
|
||
|
||
# ---------- стенд ----------
|
||
|
||
secrets:
|
||
sh scripts/init-secrets.sh
|
||
|
||
up:
|
||
docker compose up -d --build --wait
|
||
|
||
# Без -v: volumes с данными сохраняются. Удаление данных — только осознанно: docker compose down -v
|
||
down:
|
||
docker compose --profile ttl --profile tools down
|
||
|
||
# ID контейнера + время работы: после restart hook ID те же (не пересозданы), а Up сбросился.
|
||
ps:
|
||
docker compose ps -a --format "table {{.Service}}\t{{.ID}}\t{{.Status}}"
|
||
|
||
logs:
|
||
docker compose logs --tail 50 api
|
||
|
||
# ---------- собственные проверки ----------
|
||
|
||
student-test:
|
||
$(PYTHON) -m unittest discover -s student-tests -p "test_*.py" -v
|
||
|
||
race:
|
||
$(PYTHON) student-tests/race.py
|
||
|
||
expiry:
|
||
docker compose --profile ttl up -d --wait api-short-ttl
|
||
$(PYTHON) student-tests/expiry.py
|
||
|
||
failure-valkey:
|
||
$(PYTHON) student-tests/dependency_failure.py valkey
|
||
|
||
failure-postgres:
|
||
$(PYTHON) student-tests/dependency_failure.py postgres
|
||
|
||
# Valkey на паузе (данные в нём сохраняются), logout, снова в строю: токен должен остаться отозванным.
|
||
failure-valkey-pause:
|
||
$(PYTHON) student-tests/cache_revocation.py
|
||
|
||
db-test:
|
||
docker compose --profile tools run --rm db-test
|
||
|
||
explain:
|
||
docker compose exec -T postgres psql -X -q -U messenger -d messenger -v ON_ERROR_STOP=1 < infra/sql/explain_history.sql
|
||
|
||
demo:
|
||
$(PYTHON) student-tests/demo.py
|
||
|
||
# Роль Valkey: сколько ключей-сессий в кэше и сколько попаданий/промахов; права пользователя health.
|
||
VALKEY_HEALTH = docker compose exec -T valkey valkey-cli --user health --pass none --no-auth-warning
|
||
cache-stats:
|
||
$(VALKEY_HEALTH) dbsize
|
||
$(VALKEY_HEALTH) info stats | grep -E "keyspace_(hits|misses)"
|
||
-$(VALKEY_HEALTH) get sess:anything
|