Files
mtusi2026lab3/evidence/replicas/test-persistence.md
T
ricoromaandClaude Opus 5.5 de93056eab docs: add replicas-lb evidence and report
Evidence from 4e0cc4e: stand ports, limits and per-service env,
X-Instance-Id distribution and scaling, LB-generated errors,
test-persistence through the LB, test-failover for each replica in stop
and kill modes, stop-one refusals, test runs and bench self-checks.
REPORT.md gains the LB architecture, timeout chain, limits, criteria
rows and defence answers. Coverage exclusions for restart now point to
the lab 3 persistence evidence; stale lab 2 pointers go to
KNOWN_ISSUES.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-10 18:31:18 +03:00

82 lines
5.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# `make test-persistence` через балансировщик
| | |
|---|---|
| Спеки | `container-run` «Данные переживают рестарт стенда» — «Рестарт hook-ом», «Публичная проверка сохранности»; `sessions` «Прежний токен после рестарта»; `data-storage` «Прежний пользователь после рестарта» |
| Change | `replicas-lb`, задача 6.1 |
| Дата | 2026-10-10 15:22:14–15:22:23 UTC |
| Commit | `4e0cc4e` |
| Стенд | `make run_docker`: проект `mtusi-lab3`, HAProxy на `127.0.0.1:8080`, `api` × 2; тест ходит через LB (`BASE_URL` по умолчанию) |
| Хост | Docker Desktop 29.8.1, macOS arm64; ВМ Docker: 12 CPU, 7,7 GiB RAM; ноутбук от батареи |
`scripts/restart.sh`: `stop haproxy api` → `restart postgres valkey` →
`up -d --wait postgres valkey` → `start api haproxy`. Volumes не
удаляются, данные не наполняются заново. Тест создаёт данные и сессию,
вызывает hook, ждёт готовности через LB и проверяет те же данные
прежним токеном.
```text
$ docker compose ps -a (до) # сервис, контейнер, ID, состояние, StartedAt
api /mtusi-lab3-api-1 0a93eeb192b4 running exit=0 started=2026-10-10T15:21:58.273921301Z
api /mtusi-lab3-api-2 47a14cfd6cd7 running exit=0 started=2026-10-10T15:21:58.203705842Z
haproxy /mtusi-lab3-haproxy-1 5ab61b8f1958 running exit=0 started=2026-10-10T15:07:49.288248255Z
migrate /mtusi-lab3-migrate-1 7932e099b9f9 exited exit=0 started=2026-10-10T15:07:47.582119254Z
postgres /mtusi-lab3-postgres-1 e32b3661ee3a running exit=0 started=2026-10-10T15:07:45.738258545Z
valkey /mtusi-lab3-valkey-1 ae69bdd041cb running exit=0 started=2026-10-10T15:07:45.76904342Z
$ docker volume inspect -f "{{.Name}} {{.CreatedAt}}" mtusi-lab3_postgres_data
mtusi-lab3_postgres_data 2026-10-10T14:03:26Z
$ make test-persistence ACTION_SCRIPT=scripts/restart.sh
python3 tests/resilience.py --mode persistence --action-script "scripts/restart.sh" --base-url "http://localhost:8080"
Executing explicit persistence hook; hook output suppressed to avoid leaking secrets.
PASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence.
exit=0 за 7.1 с
$ docker compose ps -a (после)
api /mtusi-lab3-api-1 0a93eeb192b4 running exit=0 started=2026-10-10T15:22:20.985687089Z
api /mtusi-lab3-api-2 47a14cfd6cd7 running exit=0 started=2026-10-10T15:22:20.908433172Z
haproxy /mtusi-lab3-haproxy-1 5ab61b8f1958 running exit=0 started=2026-10-10T15:22:21.059614505Z
migrate /mtusi-lab3-migrate-1 7932e099b9f9 exited exit=0 started=2026-10-10T15:22:18.810355546Z
postgres /mtusi-lab3-postgres-1 e32b3661ee3a running exit=0 started=2026-10-10T15:22:16.963877587Z
valkey /mtusi-lab3-valkey-1 ae69bdd041cb running exit=0 started=2026-10-10T15:22:16.992591753Z
$ docker volume inspect -f "{{.Name}} {{.CreatedAt}}" mtusi-lab3_postgres_data
mtusi-lab3_postgres_data 2026-10-10T14:03:26Z
```
| Сервис | Контейнер | `StartedAt` до | `StartedAt` после |
|---|---|---|---|
| haproxy | `5ab61b8f1958` | 15:07:49.288 | 15:22:21.060 |
| api | `0a93eeb192b4` | 15:21:58.274 | 15:22:20.986 |
| api | `47a14cfd6cd7` | 15:21:58.204 | 15:22:20.908 |
| postgres | `e32b3661ee3a` | 15:07:45.738 | 15:22:16.964 |
| valkey | `ae69bdd041cb` | 15:07:45.769 | 15:22:16.993 |
| migrate | `7932e099b9f9` | 15:07:47.582 | 15:22:18.810 (повторный прогон — no-op) |
Перезапущены LB, обе реплики API, Postgres и Valkey: те же ID
контейнеров, новое время старта у всех. Число реплик не изменилось,
volume Postgres — тот же (дата создания прежняя).
## Журнал LB за окно рестарта
```text
api/api-1: IP changed from '(none)' to '172.30.0.5' by 'docker/dns'.
api/api-2: IP changed from '(none)' to '172.30.0.4' by 'DNS cache'.
Server api/api-1 ('api') is DOWN/READY (resolves again).
Server api/api-1 administratively READY thanks to valid DNS answer.
Server api/api-2 ('api') is DOWN/READY (resolves again).
Server api/api-2 administratively READY thanks to valid DNS answer.
172.30.0.1:61326 [10/Oct/2026:15:22:21.185] entry api/<NOSRV> 0/-1/-1/-1/0 503 0 - - SC-- 1/1/0/0/0 0/0 "GET /health/ready HTTP/1.1"
172.30.0.1:61342 [10/Oct/2026:15:22:21.693] entry api/<NOSRV> 0/-1/-1/-1/0 503 0 - - SC-- 1/1/0/0/0 0/0 "GET /health/ready HTTP/1.1"
Server api/api-1 is UP, reason: Layer7 check passed, code: 200, check duration: 29ms. 1 active and 0 backup servers online. 0 sessions requeued, 0 total in queue.
$ make instances # через 2 с после теста
0a93eeb192b4: 6
47a14cfd6cd7: 6
instances: 2
```
Пока реплики не прошли проверку `/health/ready`, тест получал 503 от
LB на `/health/ready` и ждал (до 90 с по `tests/README.md`). Реплики
начинают в `DOWN` (`init-state down`), поэтому запросы не уходили на
процесс, который ещё не слушает порт. Через 2 с после теста обе реплики
снова в распределении.