created skeleton for lab 6
This commit is contained in:
@@ -1,13 +1,80 @@
|
||||
PYTHON ?= python3
|
||||
BASE_URL ?= http://localhost:8080
|
||||
-include .env
|
||||
|
||||
PYTHON ?= $(if $(wildcard .venv/bin/python),.venv/bin/python,$(if $(wildcard venv/bin/python),venv/bin/python,python3))
|
||||
PYTEST_ARGS ?=
|
||||
BASE_URL ?= http://localhost:$(or $(LB_HOST_PORT),8080)
|
||||
CA_FILE ?=
|
||||
SERVICE ?=
|
||||
ACTION_SCRIPT ?=
|
||||
TLS_ARGS = $(if $(CA_FILE),--ca-file "$(CA_FILE)",)
|
||||
COMPOSE = docker compose --env-file .env
|
||||
|
||||
.PHONY: help check validate test load test-persistence test-failover
|
||||
TEST_PROJECT ?= messenger-test
|
||||
TEST_LB_PORT ?= 28080
|
||||
TEST_DB_PORT ?= $(DB_HOST_PORT)
|
||||
TEST_REDIS_PORT ?= $(REDIS_HOST_PORT)
|
||||
TEST_BASE_URL = http://localhost:$(TEST_LB_PORT)
|
||||
TEST_ENV = COMPOSE_PROJECT_NAME=$(TEST_PROJECT) COMPOSE_FILE=compose.yaml:compose.test.yaml \
|
||||
LB_HOST_PORT=$(TEST_LB_PORT) DB_HOST_PORT=$(TEST_DB_PORT) REDIS_HOST_PORT=$(TEST_REDIS_PORT)
|
||||
TEST_COMPOSE = $(TEST_ENV) $(COMPOSE)
|
||||
|
||||
TEST_DB_PASSWORD = $(if $(wildcard secrets/db_password),$(file <secrets/db_password),$(DB_PASSWORD))
|
||||
TEST_DATABASE_URL ?= postgresql+asyncpg://$(DB_USER):$(TEST_DB_PASSWORD)@localhost:$(TEST_DB_PORT)/$(DB_NAME)_test
|
||||
TEST_REDIS_HOST ?= localhost
|
||||
TEST_REDIS_PASSWORD ?= $(if $(wildcard secrets/redis_password),$(file <secrets/redis_password),$(REDIS_PASSWORD))
|
||||
TEST_REDIS_DB ?= 15
|
||||
export TEST_DATABASE_URL TEST_REDIS_HOST TEST_REDIS_PORT TEST_REDIS_PASSWORD TEST_REDIS_DB
|
||||
|
||||
.PHONY: help init up down restart ps logs migrate migration worker-stop worker-start \
|
||||
cleanup-dry-run cleanup-apply check validate test load test-unit test-pipeline \
|
||||
test-nginx test-storage test-outbox test-jobs test-persistence test-failover \
|
||||
test-suite test-stand-up test-stand-destroy
|
||||
|
||||
help:
|
||||
@echo "check: offline structure; validate: full OpenAPI (requirements-dev.txt); test: running API; load: synthetic writes"
|
||||
@echo "Запуск: init | up | down | restart | ps | logs SERVICE=worker"
|
||||
@echo "Обслуживание: migrate | migration m='описание' | worker-stop | worker-start"
|
||||
@echo "Очистка объектов: cleanup-dry-run | cleanup-apply"
|
||||
@echo "Проверки: check | validate | test | test-pipeline | test-unit PYTEST_ARGS=..."
|
||||
@echo "Нагрузка: load BASE_URL=..."
|
||||
@echo "Сервисы: test-nginx | test-storage | test-outbox | test-jobs"
|
||||
@echo "Отказы API (по запросу): test-persistence | test-failover"
|
||||
@echo "Автономный прогон с удалением тестового стенда: test-suite"
|
||||
|
||||
init:
|
||||
$(PYTHON) scripts/init_local.py
|
||||
|
||||
up:
|
||||
$(COMPOSE) up -d --build --wait --wait-timeout 120
|
||||
|
||||
down:
|
||||
$(COMPOSE) down
|
||||
|
||||
restart:
|
||||
scripts/restart.sh
|
||||
|
||||
ps:
|
||||
$(COMPOSE) ps $(SERVICE)
|
||||
|
||||
logs:
|
||||
$(COMPOSE) logs -f $(SERVICE)
|
||||
|
||||
migrate:
|
||||
$(COMPOSE) run --rm --build migrate
|
||||
|
||||
migration:
|
||||
DB_HOST=localhost DB_PORT=$(TEST_DB_PORT) $(PYTHON) -m alembic revision --autogenerate -m "$(m)"
|
||||
|
||||
worker-stop:
|
||||
$(COMPOSE) stop worker
|
||||
|
||||
worker-start:
|
||||
$(COMPOSE) start worker
|
||||
|
||||
cleanup-dry-run:
|
||||
$(COMPOSE) run --rm --no-deps cleanup python -m app.core.cleanup --once
|
||||
|
||||
cleanup-apply:
|
||||
$(COMPOSE) run --rm --no-deps cleanup python -m app.core.cleanup --once --apply
|
||||
|
||||
check:
|
||||
$(PYTHON) scripts/check_contract.py
|
||||
@@ -21,10 +88,46 @@ test:
|
||||
load:
|
||||
$(PYTHON) tests/load.py --base-url "$(BASE_URL)" $(TLS_ARGS)
|
||||
|
||||
# Все сохранённые регрессионные тесты запускаются явно; PYTEST_ARGS выбирает подмножество.
|
||||
test-unit:
|
||||
$(TEST_ENV) $(PYTHON) -m pytest -q $(PYTEST_ARGS)
|
||||
|
||||
test-pipeline:
|
||||
$(TEST_ENV) $(PYTHON) -m pytest -q student-tests/test_attachments.py student-tests/test_jobs.py student-tests/test_image_pipeline.py $(PYTEST_ARGS)
|
||||
|
||||
test-nginx:
|
||||
$(PYTHON) scripts/check_nginx.py
|
||||
|
||||
test-storage:
|
||||
$(PYTHON) -m scripts.check_s3 --base-url "$(BASE_URL)" $(TLS_ARGS)
|
||||
|
||||
test-outbox:
|
||||
$(PYTHON) -m scripts.check_outbox_recovery --base-url "$(BASE_URL)" $(TLS_ARGS)
|
||||
|
||||
test-jobs:
|
||||
$(PYTHON) -m scripts.check_jobs --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)
|
||||
$(PYTHON) tests/resilience.py --mode persistence --action-script "$(or $(ACTION_SCRIPT),scripts/restart.sh)" --base-url "$(BASE_URL)" $(TLS_ARGS)
|
||||
|
||||
test-failover:
|
||||
@test -n "$(ACTION_SCRIPT)" || (echo "Set ACTION_SCRIPT to your implemented executable stop-one hook"; exit 2)
|
||||
$(PYTHON) tests/resilience.py --mode failover --action-script "$(ACTION_SCRIPT)" --base-url "$(BASE_URL)" $(TLS_ARGS)
|
||||
$(PYTHON) tests/resilience.py --mode failover --action-script "$(or $(ACTION_SCRIPT),scripts/stop-one.sh)" --base-url "$(BASE_URL)" $(TLS_ARGS)
|
||||
|
||||
# Отдельные PostgreSQL/Redis нужны для локальных тестов; тестовая БД создаётся явно.
|
||||
test-stand-up:
|
||||
$(TEST_COMPOSE) up -d --build --wait --wait-timeout 120
|
||||
$(TEST_COMPOSE) exec -T postgres sh -c 'psql -U "$$POSTGRES_USER" -d postgres -tAc "SELECT 1 FROM pg_database WHERE datname = '\''$${POSTGRES_DB}_test'\''" | grep -q 1 || createdb -U "$$POSTGRES_USER" "$${POSTGRES_DB}_test"'
|
||||
|
||||
test-stand-destroy:
|
||||
$(TEST_COMPOSE) down --volumes --remove-orphans
|
||||
|
||||
# Проверки текущего pipeline; полный регрессионный набор и отказы API — отдельные цели.
|
||||
test-suite:
|
||||
@set -eu; trap '$(TEST_COMPOSE) down --volumes --remove-orphans' EXIT; \
|
||||
$(MAKE) check validate; \
|
||||
$(MAKE) test-stand-up; \
|
||||
$(TEST_ENV) $(MAKE) test-pipeline; \
|
||||
$(TEST_ENV) $(MAKE) test BASE_URL="$(TEST_BASE_URL)"; \
|
||||
$(TEST_ENV) $(MAKE) test-storage BASE_URL="$(TEST_BASE_URL)"; \
|
||||
$(TEST_ENV) $(MAKE) test-outbox BASE_URL="$(TEST_BASE_URL)"; \
|
||||
$(TEST_ENV) $(MAKE) test-jobs BASE_URL="$(TEST_BASE_URL)";
|
||||
|
||||
Reference in New Issue
Block a user