feat: реализация второй лабы по тз

This commit is contained in:
Enterxx2
2026-10-11 18:14:20 +03:00
parent a6c74c9bb0
commit ea2b432a22
100 changed files with 3416 additions and 428 deletions
+41 -36
View File
@@ -4,19 +4,12 @@ CA_FILE ?=
ACTION_SCRIPT ?=
TLS_ARGS = $(if $(CA_FILE),--ca-file "$(CA_FILE)",)
ENV_FILE ?= .env
-include $(ENV_FILE)
IMAGE ?= mtusi-messenger:lab2
CONTAINER ?= mtusi-messenger-lab2
PUBLISH ?= 127.0.0.1:$(APP_PORT):$(APP_PORT)
READY_TIMEOUT_SEC ?= 30
POETRY ?= poetry
.PHONY: help check validate test load test-persistence install build run wait-ready stop restart logs student-test concurrency-test sigterm-check up_local down_local
.PHONY: help check validate test load test-persistence install up down restart ps logs wait-ready destroy-data student-test concurrency-test test-expiry test-failures test-migrations explain sigterm-check
help:
@echo "check: offline structure; validate: full OpenAPI (requirements-dev.txt); test: running API; load: synthetic writes"
@echo "install: dev venv; build/run/stop/restart/logs: container; up_local/down_local: docker compose; student-test: own tests; concurrency-test, sigterm-check: evidence"
@echo "up/down/restart/ps/logs: compose stack; destroy-data: DELETE volumes intentionally"
@echo "student-test: own tests; test-migrations: from empty volume; test-expiry: short SESSION_TTL; test-failures: stop Valkey/PostgreSQL; explain: EXPLAIN history"
check:
$(PYTHON) scripts/check_contract.py
@@ -35,42 +28,54 @@ test-persistence:
$(PYTHON) tests/resilience.py --mode persistence --action-script "$(ACTION_SCRIPT)" --base-url "$(BASE_URL)" $(TLS_ARGS)
install:
$(POETRY) install --no-root
poetry install --no-root
build:
docker build -t $(IMAGE) .
up:
docker compose up -d --build --wait
run:
docker run --rm -d --name $(CONTAINER) -p $(PUBLISH) --env-file $(ENV_FILE) $(IMAGE)
@$(MAKE) --no-print-directory wait-ready
wait-ready:
@for i in $$(seq 1 $(READY_TIMEOUT_SEC)); do \
curl -fsS "$(BASE_URL)/health/ready" >/dev/null 2>&1 && echo "ready: $(BASE_URL)" && exit 0; \
sleep 1; \
done; echo "API is not ready after $(READY_TIMEOUT_SEC)s"; exit 1
stop:
docker stop $(CONTAINER)
down:
docker compose --profile expiry down
restart:
docker restart $(CONTAINER)
./scripts/restart.sh
@$(MAKE) --no-print-directory wait-ready
ps:
docker compose ps
logs:
docker logs -f $(CONTAINER)
docker compose logs -f api
wait-ready:
@for i in $$(seq 1 60); do \
curl -fsS "$(BASE_URL)/health/ready" >/dev/null 2>&1 && echo "ready: $(BASE_URL)" && exit 0; \
sleep 1; \
done; echo "API is not ready after 60s"; exit 1
destroy-data:
docker compose --profile expiry down -v
student-test:
BASE_URL="$(BASE_URL)" $(POETRY) run pytest
BASE_URL="$(BASE_URL)" poetry run pytest
concurrency-test:
BASE_URL="$(BASE_URL)" $(POETRY) run pytest student-tests/test_concurrency.py -s
BASE_URL="$(BASE_URL)" poetry run pytest student-tests/test_concurrency.py -s
test-expiry:
docker compose --profile expiry up -d --build --wait api-short-ttl
EXPIRY_BASE_URL=http://localhost:8081 poetry run pytest student-tests/test_expiry.py -s; \
status=$$?; docker compose --profile expiry stop api-short-ttl; exit $$status
test-failures:
BASE_URL="$(BASE_URL)" RUN_FAILURE_TESTS=1 poetry run pytest student-tests/test_dependency_failures.py -s
test-migrations:
./scripts/check_migrations.sh
explain:
docker compose exec -T postgres sh -c 'psql -X -q -v ON_ERROR_STOP=1 -U "$$POSTGRES_USER" -d "$$POSTGRES_DB"' \
< scripts/explain_history.sql > evidence/explain_history.txt
@echo "saved: evidence/explain_history.txt"
sigterm-check:
CONTAINER="$(CONTAINER)" $(PYTHON) scripts/sigterm_check.py --base-url "$(BASE_URL)"
up_local:
docker compose -f docker-compose-local.yaml up --build -d
down_local:
docker compose -f docker-compose-local.yaml down
$(PYTHON) scripts/sigterm_check.py --base-url "$(BASE_URL)"