Durable staging handoff, transactional outbox, at-least-once worker with lease fencing, idempotent versioned pipeline, three variants, operator tooling, contract tests and evidence. Includes the review fixes: reprocess source selection and failure settlement, replay guards, stale-job retirement, PNG structural/raster validation, migration rollback safety and audit events.
178 lines
6.2 KiB
Makefile
178 lines
6.2 KiB
Makefile
PYTHON ?= python3
|
|
BASE_URL ?= http://localhost:8080
|
|
CA_FILE ?=
|
|
ACTION_SCRIPT ?=
|
|
PIPELINE ?= 2
|
|
TLS_ARGS = $(if $(CA_FILE),--ca-file "$(CA_FILE)",)
|
|
PYTHON_LOCAL = env -u HTTP_PROXY -u HTTPS_PROXY -u ALL_PROXY -u http_proxy -u https_proxy -u all_proxy NO_PROXY=localhost,127.0.0.1,::1 no_proxy=localhost,127.0.0.1,::1 $(PYTHON)
|
|
|
|
.PHONY: help check validate test test-attachments test-presign load test-persistence test-failover smoke-local load-local test-idempotency test-lb-readiness up down ps logs
|
|
|
|
help:
|
|
@echo "check: offline structure; validate: full OpenAPI (requirements-dev.txt); test: running API; load: synthetic writes"
|
|
@echo "up/down/ps/logs: lab3 stand from compose.yaml (LB + API_REPLICAS replicas + stores)"
|
|
|
|
check:
|
|
$(PYTHON) scripts/check_contract.py
|
|
$(PYTHON) scripts/check_s3_creds.py
|
|
|
|
validate:
|
|
$(PYTHON) scripts/validate_openapi.py
|
|
|
|
test:
|
|
$(PYTHON_LOCAL) tests/smoke.py --base-url "$(BASE_URL)" $(TLS_ARGS)
|
|
|
|
test-attachments:
|
|
$(PYTHON_LOCAL) student-tests/attachments_negative.py --base-url "$(BASE_URL)" $(TLS_ARGS)
|
|
|
|
test-presign:
|
|
$(PYTHON_LOCAL) student-tests/presign_flow.py --base-url "$(BASE_URL)" $(TLS_ARGS)
|
|
|
|
test-queue:
|
|
$(PYTHON_LOCAL) student-tests/lab5_async.py --base-url "$(BASE_URL)" $(TLS_ARGS)
|
|
|
|
test-faults:
|
|
$(PYTHON_LOCAL) student-tests/lab5_faults.py --base-url "$(BASE_URL)" $(TLS_ARGS)
|
|
|
|
test-track2:
|
|
$(PYTHON_LOCAL) scripts/lab5_track2.py --base-url "$(BASE_URL)" $(TLS_ARGS)
|
|
|
|
load:
|
|
$(PYTHON_LOCAL) 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_LOCAL) tests/resilience.py --mode persistence --action-script "$(ACTION_SCRIPT)" --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_LOCAL) tests/resilience.py --mode failover --action-script "$(ACTION_SCRIPT)" --base-url "$(BASE_URL)" $(TLS_ARGS)
|
|
|
|
# Локальный запуск без прокси: в окружении автора HTTP(S)_PROXY ломает localhost.
|
|
smoke-local:
|
|
$(PYTHON_LOCAL) tests/smoke.py --base-url "$(BASE_URL)" $(TLS_ARGS)
|
|
|
|
load-local:
|
|
$(PYTHON_LOCAL) tests/load.py --base-url "$(BASE_URL)" $(TLS_ARGS)
|
|
|
|
# Собственная проверка уровня 4: параллельные повторы одного Idempotency-Key
|
|
# через LB обязаны создать ровно одно сообщение.
|
|
test-idempotency:
|
|
$(PYTHON_LOCAL) student-tests/idempotency_parallel.py --base-url "$(BASE_URL)" $(TLS_ARGS)
|
|
|
|
# Собственная проверка уровня 4: LB обязан убрать из ротации реплику, которая
|
|
# осталась доступной, но потеряла БД (readiness 503).
|
|
test-lb-readiness:
|
|
scripts/lb_readiness_check.sh
|
|
|
|
COMPOSE_BIN ?= docker compose
|
|
COMPOSE_FILE ?= compose.yaml
|
|
ENV_FILE ?= .env
|
|
|
|
up:
|
|
$(COMPOSE_BIN) --env-file $(ENV_FILE) -f $(COMPOSE_FILE) up -d --build
|
|
|
|
down:
|
|
$(COMPOSE_BIN) --env-file $(ENV_FILE) -f $(COMPOSE_FILE) down
|
|
|
|
ps:
|
|
$(COMPOSE_BIN) --env-file $(ENV_FILE) -f $(COMPOSE_FILE) ps
|
|
|
|
logs:
|
|
$(COMPOSE_BIN) --env-file $(ENV_FILE) -f $(COMPOSE_FILE) logs -f --tail 100
|
|
|
|
# Operator views: the failed registry is PostgreSQL, the DLQ is a backstop.
|
|
jobs-failed:
|
|
$(COMPOSE_BIN) --env-file $(ENV_FILE) -f $(COMPOSE_FILE) run --rm --entrypoint /usr/local/bin/jobctl worker failed
|
|
|
|
replay:
|
|
@test -n "$(JOB)" || (echo "Set JOB=<job_id>"; exit 2)
|
|
$(COMPOSE_BIN) --env-file $(ENV_FILE) -f $(COMPOSE_FILE) run --rm --entrypoint /usr/local/bin/jobctl worker replay -job "$(JOB)"
|
|
|
|
reprocess:
|
|
@test -n "$(ATTACHMENT)" || (echo "Set ATTACHMENT=<attachment_id>"; exit 2)
|
|
$(COMPOSE_BIN) --env-file $(ENV_FILE) -f $(COMPOSE_FILE) run --rm --entrypoint /usr/local/bin/jobctl worker reprocess -attachment "$(ATTACHMENT)" -pipeline "$(PIPELINE)"
|
|
|
|
.DEFAULT_GOAL := help
|
|
GO ?= go
|
|
APP_NAME ?= messenger
|
|
CMD_PKG := ./cmd/$(APP_NAME)
|
|
LOCAL_BIN := $(CURDIR)/bin
|
|
GOLANGCI_LINT_VERSION ?= v2.13.2
|
|
GOLANGCI_LINT := $(LOCAL_BIN)/golangci-lint
|
|
OPENAPI_SPEC := contracts/openapi.json
|
|
OGEN_CONFIG := .ogen.yml
|
|
OAS_DIR := internal/transport/rest/internal/oas
|
|
|
|
-include .env
|
|
export
|
|
|
|
# .env feeds local tooling, but its application variables must not leak into the
|
|
# Go test process: the config tests assert defaults and the dev YAML, so an
|
|
# ambient REDIS_ENABLED/CACHE_ENABLED would fail them.
|
|
ENV_KEYS := $(shell sed -n 's/^\([A-Za-z_][A-Za-z0-9_]*\)=.*/\1/p' .env 2>/dev/null)
|
|
CLEAN_ENV = env $(addprefix -u ,$(ENV_KEYS))
|
|
|
|
.PHONY: unit-test
|
|
unit-test:
|
|
$(CLEAN_ENV) $(GO) test -race -shuffle=on -count=1 -timeout=5m ./...
|
|
|
|
.PHONY: integration-test
|
|
integration-test:
|
|
$(GO) test -tags=integration -p 1 -count=1 -timeout=15m ./internal/storage/postgres ./internal/storage/redis
|
|
|
|
.PHONY: test-db-up test-db-down
|
|
test-db-up:
|
|
@docker-compose -f docker-compose.local.yaml up -d --wait postgres redis
|
|
|
|
test-db-down:
|
|
@docker-compose -f docker-compose.local.yaml down
|
|
|
|
# не учитываем генеренные файлы, также cmd в подсчете покрытия
|
|
COVER_EXCLUDE ?= /(mocks|oas)/|/cmd/
|
|
|
|
.PHONY: cover
|
|
cover:
|
|
$(CLEAN_ENV) $(GO) test -race -shuffle=on -count=1 -timeout=5m \
|
|
-covermode=atomic -coverprofile=coverage.out.tmp ./...
|
|
@grep -Ev '$(COVER_EXCLUDE)' coverage.out.tmp > coverage.out
|
|
@rm coverage.out.tmp
|
|
$(GO) tool cover -func=coverage.out | tail -n 1
|
|
$(GO) tool cover -html=coverage.out
|
|
|
|
.PHONY: generate
|
|
generate: generate-api generate-mocks sqlc
|
|
|
|
.PHONY: generate-api
|
|
generate-api:
|
|
$(GO) run ./tools/specgen
|
|
$(GO) tool ogen --config $(OGEN_CONFIG) --target $(OAS_DIR) --package oas --clean .cache/openapi.codegen.json
|
|
|
|
.PHONY: generate-mocks
|
|
generate-mocks:
|
|
$(GO) tool mockery
|
|
|
|
.PHONY: sqlc
|
|
sqlc:
|
|
$(GO) tool sqlc generate
|
|
|
|
.PHONY: dev-up dev-down dev-reload
|
|
dev-up:
|
|
@docker-compose -f docker-compose.local.yaml up -d --build
|
|
|
|
dev-down:
|
|
@docker-compose -f docker-compose.local.yaml down
|
|
|
|
dev-reload:
|
|
@docker-compose -f docker-compose.local.yaml up -d --build --force-recreate
|
|
|
|
.PHONY: migrate
|
|
migrate:
|
|
$(GO) run ./cmd/migrate up
|
|
|
|
$(GOLANGCI_LINT):
|
|
GOBIN=$(LOCAL_BIN) $(GO) install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)
|
|
|
|
lint: $(GOLANGCI_LINT)
|
|
$(GOLANGCI_LINT) run -v
|