docs: REPORT lab2, доказательства со стенда из чистого clone, размеры индексов

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alexey Bodanyuk
2026-10-12 20:20:00 +03:00
co-authored by Claude Opus 5.5
parent eb92e8e91e
commit d65ba991d7
15 changed files with 613 additions and 25 deletions
+40
View File
@@ -0,0 +1,40 @@
# Clean clone -> build -> fresh volumes -> migrations from zero, 2026-10-12T17:08:32Z
$ git clone --branch solution/bvt2302-bodanyuk <repo> mtusi2026lab2 && cd mtusi2026lab2
eb92e8e bench: трек 2 — планы запросов, стоимость записи, backup/restore со сверкой
$ python scripts/init_secrets.py
created secrets/postgres_password
created secrets/valkey_password
created secrets/database_url
created secrets/cache_url
$ cp .env.example .env # + COMPOSE_PROJECT_NAME/APP_PUBLISH_PORT only to run beside the main stand
$ docker compose --env-file .env config --quiet
config OK
$ docker compose --env-file .env up -d --build --wait
Container mtusi-lab2-clean-api-1 Healthy
Container mtusi-lab2-clean-migrate-1 Exited
Container mtusi-lab2-clean-postgres-1 Healthy
Container mtusi-lab2-clean-valkey-1 Healthy
$ docker compose ps
SERVICE IMAGE STATUS
api mtusi-messenger:lab2 Up 6 seconds (healthy)
postgres postgres:18.6-bookworm@sha256:afc7e2d441324c0388fa80c3d24f733b4194a4eb7f47dd8ee2b08eb1a24a647c Up 13 seconds (healthy)
valkey valkey/valkey:8.1.3-bookworm@sha256:fea8b3e67b15729d4bb70589eb03367bab9ad1ee89c876f54327fc7c6e618571 Up 13 seconds (healthy)
$ docker compose logs migrate
migrate: 0001_init: applied
migrate: done, 1 migration file(s) checked
$ docker compose volume ls
mtusi-lab2-clean_pgdata
mtusi-lab2-clean_valkeydata
$ curl -i http://127.0.0.1:8081/health/ready
HTTP/1.1 200 OK
x-request-id: 38be4c9665124450b66c5d9218c596d9
{"status":"ok"}
$ docker compose exec api id; PID 1
uid=10001(app) gid=10001(app) groups=10001(app)
PID 1: python -m messenger
$ docker compose run --rm migrate # second run: idempotent
migrate: 0001_init: already applied, skipped
migrate: done, 1 migration file(s) checked
$ git status --short # secrets/.env must not be tracked
secrets/database_url
.env
+63
View File
@@ -0,0 +1,63 @@
$ python scripts/explain_history.py --output evidence/explain-history.txt
messages_total | messages_in_target_chat
----------------+-------------------------
50146 | 20000
(1 row)
=== 1. first page, app query HISTORY_FIRST, generic plan
QUERY PLAN
------------------------------------------------------------------------------------------------------------------------------------------------
Limit (cost=0.41..122.63 rows=119 width=55) (actual time=0.019..0.030 rows=51.00 loops=1)
Buffers: shared hit=4
-> Index Scan using messages_chat_keyset on messages (cost=0.41..1226.64 rows=1194 width=55) (actual time=0.017..0.025 rows=51.00 loops=1)
Index Cond: (chat_id = $1)
Index Searches: 1
Buffers: shared hit=4
Planning:
Buffers: shared hit=10
Planning Time: 0.157 ms
Execution Time: 0.067 ms
(10 rows)
=== 2. late page (cursor at 19950), app query HISTORY_AFTER, generic plan
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------------------
Limit (cost=0.41..59.95 rows=40 width=55) (actual time=0.022..0.036 rows=50.00 loops=1)
Buffers: shared hit=5
-> Index Scan using messages_chat_keyset on messages (cost=0.41..592.75 rows=398 width=55) (actual time=0.020..0.030 rows=50.00 loops=1)
Index Cond: ((chat_id = $1) AND (ROW(created_at, id) > ROW($2, $3)))
Index Searches: 1
Buffers: shared hit=5
Planning Time: 0.163 ms
Execution Time: 0.112 ms
(8 rows)
=== 3. REJECTED: one query with ($2 IS NULL OR ...), same late page, generic plan
QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------------------------------
Limit (cost=0.41..123.02 rows=40 width=55) (actual time=3.242..3.257 rows=50.00 loops=1)
Buffers: shared hit=526
-> Index Scan using messages_chat_keyset on messages (cost=0.41..1232.61 rows=402 width=55) (actual time=3.239..3.251 rows=50.00 loops=1)
Index Cond: (chat_id = $1)
Filter: (($2 IS NULL) OR (ROW(created_at, id) > ROW($2, $3)))
Rows Removed by Filter: 19950
Index Searches: 1
Buffers: shared hit=526
Planning Time: 0.125 ms
Execution Time: 3.282 ms
(10 rows)
=== 4. REJECTED: OFFSET pagination, same late page
QUERY PLAN
---------------------------------------------------------------------------------------------------------------------------------------------------
Limit (cost=122.63..244.84 rows=119 width=55) (actual time=4.404..4.418 rows=50.00 loops=1)
Buffers: shared hit=526
-> Index Scan using messages_chat_keyset on messages (cost=0.41..1226.64 rows=1194 width=55) (actual time=0.015..3.790 rows=20000.00 loops=1)
Index Cond: (chat_id = $1)
Index Searches: 1
Buffers: shared hit=526
Planning Time: 0.091 ms
Execution Time: 4.438 ms
(8 rows)
+22
View File
@@ -0,0 +1,22 @@
# api log checks after smoke + valkey pause + unicode/NUL + wrong password tests, 2026-10-12T17:15:19Z
lines in api log: 93
message texts sent by tests ('Привет, мир', 'Сообщение Боба', 'до отказа', 'hello', 'чужое') found: 0
test passwords ('Test-password', 'T3st-') found: 0
Authorization values (Bearer/Basic + credential) found: 0
postgres/valkey passwords found: 0
event types:
62 "event": "request"
8 "event": "user_created"
7 "event": "session_created"
3 "event": "session_store_unavailable"
3 "event": "login_failed"
3 "event": "chat_created"
1 "event": "starting"
1 "event": "session_revoked"
1 "event": "dependencies_configured"
sample lines:
{"ts": "2026-10-12T17:15:10.934Z", "level": "info", "logger": "messenger", "event": "login_failed", "request_id": "350860a9d9ef4ad4b7fd6a9be0964981"}
{"ts": "2026-10-12T17:15:10.963Z", "level": "info", "logger": "messenger", "event": "session_revoked", "request_id": "5e8711e330724ed2a09f734947793877"}
{"ts": "2026-10-12T17:15:13.849Z", "level": "warning", "logger": "messenger.sessions", "event": "session_store_unavailable", "error": "TimeoutError"}
{"ts": "2026-10-12T17:15:13.850Z", "level": "info", "logger": "messenger.access", "event": "request", "request_id": "14fd3d975da3447e855d860eec8b1832", "method": "GET", "path": "/api/v1/users/me", "status": 503, "duration_ms": 501.281}
{"ts": "2026-10-12T17:15:14.354Z", "level": "info", "logger": "messenger.access", "event": "request", "request_id": "e2ddf53f97a1403fbb635d94d52ea9ad", "method": "GET", "path": "/api/v1/chats/3d96c3ee-a9c8-46eb-b8fe-7f12ba8ec2f0/messages", "status": 503, "duration_ms": 503.088}
+4
View File
@@ -0,0 +1,4 @@
$ make check # python scripts/check_contract.py
PASS: offline skeleton structure, local refs and Python syntax; application NOT tested.
$ make validate # (venv with requirements-dev.txt)
PASS: full OpenAPI 3.1 and JSON Schema validation; application NOT tested.
+2
View File
@@ -0,0 +1,2 @@
$ make test BASE_URL=http://127.0.0.1:8081
PASS: lab2 public API scenario; infrastructure and grading evidence remain separate.
+20
View File
@@ -0,0 +1,20 @@
$ sh scripts/restart.sh # what the hook does (run by hand to see its output)
Container mtusi-lab2-clean-api-1 Stopping
Container mtusi-lab2-clean-api-1 Stopped
Container mtusi-lab2-clean-postgres-1 Restarting
Container mtusi-lab2-clean-valkey-1 Restarting
Container mtusi-lab2-clean-valkey-1 Started
Container mtusi-lab2-clean-postgres-1 Started
Container mtusi-lab2-clean-postgres-1 Waiting
Container mtusi-lab2-clean-postgres-1 Healthy
Container mtusi-lab2-clean-migrate-1 Starting
Container mtusi-lab2-clean-migrate-1 Started
Container mtusi-lab2-clean-postgres-1 Waiting
Container mtusi-lab2-clean-valkey-1 Waiting
Container mtusi-lab2-clean-migrate-1 Waiting
Container mtusi-lab2-clean-valkey-1 Healthy
Container mtusi-lab2-clean-postgres-1 Healthy
Container mtusi-lab2-clean-migrate-1 Exited
Container mtusi-lab2-clean-api-1 Starting
Container mtusi-lab2-clean-api-1 Started
restart.sh: api, postgres and valkey restarted with volumes preserved
+8
View File
@@ -0,0 +1,8 @@
# SIGTERM (docker compose stop = SIGTERM, then SIGKILL after stop_grace_period 10s)
run 1: docker compose stop api -> 1195 ms, exit code 0, OOMKilled=false
run 2: docker compose stop api -> 1089 ms, exit code 0, OOMKilled=false
run 3: docker compose stop api -> 1098 ms, exit code 0, OOMKilled=false
last shutdown log lines:
{"ts": "2026-10-12T17:16:17.419Z", "level": "info", "logger": "messenger", "event": "shutdown_requested", "signal": 15, "timeout_s": 8.0}
{"ts": "2026-10-12T17:16:17.541Z", "level": "info", "logger": "uvicorn.error", "event": "Finished server process [1]"}
{"ts": "2026-10-12T17:16:17.542Z", "level": "info", "logger": "messenger", "event": "stopped"}
+117
View File
@@ -0,0 +1,117 @@
$ BASE_URL=http://127.0.0.1:8081 python -m pytest student-tests -v # stand from the clean clone
============================= test session starts =============================
platform win32 -- Python 3.14.6, pytest-9.1.1, pluggy-1.6.0 -- <repo>/.venv/Scripts/python.exe
rootdir: <clean clone of the repo>
plugins: anyio-4.15.1
collecting ... collected 108 items
student-tests/test_api.py::test_register_never_returns_password_and_login_returns_bearer PASSED
student-tests/test_api.py::test_duplicate_username_is_409 PASSED
student-tests/test_api.py::test_bad_password_on_registration_is_400[short-11ch] PASSED
student-tests/test_api.py::test_bad_password_on_registration_is_400[ ] PASSED
student-tests/test_api.py::test_bad_password_on_registration_is_400[ \t \n \t \n \t \n ] PASSED
student-tests/test_api.py::test_bad_password_on_registration_is_400[\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f] PASSED
student-tests/test_api.py::test_edge_passwords_register_and_login[\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f] PASSED
student-tests/test_api.py::test_edge_passwords_register_and_login[with:colons:inside] PASSED
student-tests/test_api.py::test_edge_passwords_register_and_login[Twelve chars] PASSED
student-tests/test_api.py::test_wrong_password_and_unknown_user_give_the_same_401 PASSED
student-tests/test_api.py::test_malformed_basic_is_401_not_500[Basic \xe9] PASSED
student-tests/test_api.py::test_malformed_basic_is_401_not_500[Basic !!!] PASSED
student-tests/test_api.py::test_malformed_basic_is_401_not_500[Basic bm9fY29sb24=] PASSED
student-tests/test_api.py::test_malformed_basic_is_401_not_500[Basic //46eA==] PASSED
student-tests/test_api.py::test_malformed_basic_is_401_not_500[Bearer aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa] PASSED
student-tests/test_api.py::test_malformed_basic_is_401_not_500[] PASSED
student-tests/test_api.py::test_logout_revokes_only_this_token PASSED
student-tests/test_api.py::test_x_user_id_basic_and_garbage_do_not_authenticate PASSED
student-tests/test_api.py::test_malformed_json_is_400[{] PASSED
student-tests/test_api.py::test_malformed_json_is_400[] PASSED
student-tests/test_api.py::test_malformed_json_is_400[[]] PASSED
student-tests/test_api.py::test_malformed_json_is_400[null] PASSED
student-tests/test_api.py::test_malformed_json_is_400[{"username": "abc_def", "display_name": NaN, "password": "Twelve-chars"}] PASSED
student-tests/test_api.py::test_malformed_json_is_400[{"username": "abc_def", "display_name": "x", "password": "Twelve-chars"}{"a": 1}] PASSED
student-tests/test_api.py::test_malformed_json_is_400[{"username": "abc_def", "display_name": "\ud800", "password": "Twelve-chars"}] PASSED
student-tests/test_api.py::test_invalid_registration_fields_are_400[body0] PASSED
student-tests/test_api.py::test_invalid_registration_fields_are_400[body1] PASSED
student-tests/test_api.py::test_invalid_registration_fields_are_400[body2] PASSED
student-tests/test_api.py::test_invalid_registration_fields_are_400[body3] PASSED
student-tests/test_api.py::test_invalid_registration_fields_are_400[body4] PASSED
student-tests/test_api.py::test_invalid_registration_fields_are_400[body5] PASSED
student-tests/test_api.py::test_unicode_limits_are_code_points_and_nul_is_stored PASSED
student-tests/test_api.py::test_oversized_body_and_wrong_content_type PASSED
student-tests/test_api.py::test_chat_validation PASSED
student-tests/test_api.py::test_foreign_chat_is_indistinguishable_from_missing PASSED
student-tests/test_api.py::test_chat_list_order_pagination_and_isolation PASSED
student-tests/test_api.py::test_history_pages_without_loss_or_duplicates PASSED
student-tests/test_api.py::test_bad_limit_or_cursor_is_400[limit=0] PASSED
student-tests/test_api.py::test_bad_limit_or_cursor_is_400[limit=101] PASSED
student-tests/test_api.py::test_bad_limit_or_cursor_is_400[limit=abc] PASSED
student-tests/test_api.py::test_bad_limit_or_cursor_is_400[limit=1&limit=2] PASSED
student-tests/test_api.py::test_bad_limit_or_cursor_is_400[cursor=] PASSED
student-tests/test_api.py::test_bad_limit_or_cursor_is_400[cursor=garbage] PASSED
student-tests/test_api.py::test_bad_limit_or_cursor_is_400[cursor=djF8bXx4fDF8Mg] PASSED
student-tests/test_api.py::test_bad_limit_or_cursor_is_400[cursor=djF8bXx4fDk5OTk5OTk5OTk5OTk5OTk5OTk5fHk=] PASSED
student-tests/test_api.py::test_cursor_bound_to_chat PASSED
student-tests/test_api.py::test_read_after_write PASSED
student-tests/test_db.py::test_registration_race_exactly_one_201_and_seven_409 PASSED
student-tests/test_db.py::test_create_chat_rolls_back_after_the_chat_row_was_inserted PASSED
student-tests/test_db.py::test_migrations_rerun_is_a_noop PASSED
student-tests/test_db.py::test_100_messages_from_10_clients_keep_order_and_cursor_walk PASSED
student-tests/test_db.py::test_secrets_are_not_stored_in_plain_text PASSED
student-tests/test_explain.py::test_late_page_uses_index_range_not_filter PASSED
student-tests/test_failures.py::test_valkey_failure[stop] PASSED
student-tests/test_failures.py::test_valkey_failure[pause] PASSED
student-tests/test_failures.py::test_postgres_failure[stop] PASSED
student-tests/test_failures.py::test_postgres_failure[pause] PASSED
student-tests/test_failures.py::test_locked_table_gives_bounded_503 PASSED
student-tests/test_failures.py::test_logout_during_valkey_outage_is_never_lost PASSED
student-tests/test_sessions.py::test_short_ttl_expires[valkey] PASSED
student-tests/test_sessions.py::test_short_ttl_expires[postgres] PASSED
student-tests/test_sessions.py::test_restart_does_not_extend_ttl PASSED
student-tests/test_sessions.py::test_postgres_session_store PASSED
student-tests/unit/test_unit.py::test_valid_passwords[Twelve-chars] PASSED
student-tests/unit/test_unit.py::test_valid_passwords[\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f] PASSED
student-tests/unit/test_unit.py::test_valid_passwords[\u043f\u0430\u0440\u043e\u043b\u044c:\u0441:\u0434\u0432\u043e\u0435\u0442\u043e\u0447\u0438\u044f\u043c\u0438] PASSED
student-tests/unit/test_unit.py::test_valid_passwords[\U0001f600\U0001f600\U0001f600\U0001f600\U0001f600\U0001f600\U0001f600\U0001f600\U0001f600\U0001f600\U0001f600\U0001f600] PASSED
student-tests/unit/test_unit.py::test_valid_passwords[a b c d e f g] PASSED
student-tests/unit/test_unit.py::test_invalid_passwords[short-11ch] PASSED
student-tests/unit/test_unit.py::test_invalid_passwords[\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f\u044f] PASSED
student-tests/unit/test_unit.py::test_invalid_passwords[ ] PASSED
student-tests/unit/test_unit.py::test_invalid_passwords[\t\n\u3000\t\n\u3000\t\n\u3000\t\n\u3000\t\n\u3000] PASSED
student-tests/unit/test_unit.py::test_invalid_passwords[\ud800\ud800\ud800\ud800\ud800\ud800\ud800\ud800\ud800\ud800\ud800\ud800] PASSED
student-tests/unit/test_unit.py::test_invalid_passwords[None] PASSED
student-tests/unit/test_unit.py::test_invalid_passwords[123456789012] PASSED
student-tests/unit/test_unit.py::test_text_may_contain_nul_but_not_lone_surrogates PASSED
student-tests/unit/test_unit.py::test_cursor_roundtrip_and_binding PASSED
student-tests/unit/test_unit.py::test_broken_cursors_are_400_not_500[v1|m|3f2c7a5e-0b7d-4a35-9a43-8d1f0f3b2c11|253402300800000000|11111111-1111-4111-8111-111111111111] PASSED
student-tests/unit/test_unit.py::test_broken_cursors_are_400_not_500[v1|m|3f2c7a5e-0b7d-4a35-9a43-8d1f0f3b2c11|9999999999999999999|11111111-1111-4111-8111-111111111111] PASSED
student-tests/unit/test_unit.py::test_broken_cursors_are_400_not_500[v1|m|3f2c7a5e-0b7d-4a35-9a43-8d1f0f3b2c11|-1|11111111-1111-4111-8111-111111111111] PASSED
student-tests/unit/test_unit.py::test_broken_cursors_are_400_not_500[v1|m|3f2c7a5e-0b7d-4a35-9a43-8d1f0f3b2c11|1|not-a-uuid] PASSED
student-tests/unit/test_unit.py::test_broken_cursors_are_400_not_500[v1|m|3f2c7a5e-0b7d-4a35-9a43-8d1f0f3b2c11|1|11111111-1111-4111-8111-11111111111G] PASSED
student-tests/unit/test_unit.py::test_broken_cursors_are_400_not_500[v2|m|3f2c7a5e-0b7d-4a35-9a43-8d1f0f3b2c11|1|11111111-1111-4111-8111-111111111111] PASSED
student-tests/unit/test_unit.py::test_time_helpers_are_exact PASSED
student-tests/unit/test_unit.py::test_basic_is_parsed_and_password_may_contain_colons PASSED
student-tests/unit/test_unit.py::test_bad_basic_is_401_with_basic_challenge[None] PASSED
student-tests/unit/test_unit.py::test_bad_basic_is_401_with_basic_challenge[] PASSED
student-tests/unit/test_unit.py::test_bad_basic_is_401_with_basic_challenge[Basic] PASSED
student-tests/unit/test_unit.py::test_bad_basic_is_401_with_basic_challenge[Basic \xe9] PASSED
student-tests/unit/test_unit.py::test_bad_basic_is_401_with_basic_challenge[Basic !!!!] PASSED
student-tests/unit/test_unit.py::test_bad_basic_is_401_with_basic_challenge[Basic bm8tY29sb24=] PASSED
student-tests/unit/test_unit.py::test_bad_basic_is_401_with_basic_challenge[Basic //46cHc=] PASSED
student-tests/unit/test_unit.py::test_bad_basic_is_401_with_basic_challenge[Basic OnBhc3N3b3Jk] PASSED
student-tests/unit/test_unit.py::test_bad_basic_is_401_with_basic_challenge[Basic YWxpY2U6] PASSED
student-tests/unit/test_unit.py::test_bad_basic_is_401_with_basic_challenge[Basic 0JDQu9C40YHQsDpwdw==] PASSED
student-tests/unit/test_unit.py::test_bad_basic_is_401_with_basic_challenge[Bearer aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa] PASSED
student-tests/unit/test_unit.py::test_bad_basic_is_401_with_basic_challenge[Basic AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA] PASSED
student-tests/unit/test_unit.py::test_bad_bearer_is_401_with_bearer_challenge[None] PASSED
student-tests/unit/test_unit.py::test_bad_bearer_is_401_with_bearer_challenge[] PASSED
student-tests/unit/test_unit.py::test_bad_bearer_is_401_with_bearer_challenge[Bearer] PASSED
student-tests/unit/test_unit.py::test_bad_bearer_is_401_with_bearer_challenge[Bearer short] PASSED
student-tests/unit/test_unit.py::test_bad_bearer_is_401_with_bearer_challenge[Bearer aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa!] PASSED
student-tests/unit/test_unit.py::test_bad_bearer_is_401_with_bearer_challenge[Basic YWxpY2U6cGFzc3dvcmQtMTIz] PASSED
student-tests/unit/test_unit.py::test_bad_bearer_is_401_with_bearer_challenge[Token aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa] PASSED
student-tests/unit/test_unit.py::test_bad_bearer_is_401_with_bearer_challenge[Bearer \xe9\xe9\xe9\xe9\xe9\xe9\xe9\xe9\xe9\xe9\xe9\xe9\xe9\xe9\xe9\xe9\xe9\xe9\xe9\xe9\xe9\xe9\xe9\xe9\xe9\xe9\xe9\xe9\xe9\xe9\xe9\xe9\xe9\xe9\xe9\xe9\xe9\xe9\xe9\xe9\xe9\xe9\xe9] PASSED
student-tests/unit/test_unit.py::test_bearer_ok PASSED
student-tests/unit/test_unit.py::test_argon2id_hash_and_verify PASSED
student-tests/unit/test_unit.py::test_settings_read_secret_files_and_contract_names PASSED
======================= 108 passed in 208.53s (0:03:28) =======================
+24
View File
@@ -0,0 +1,24 @@
# Same persistence test with SESSION_STORE=postgres (sessions in table sessions)
$ SESSION_STORE=postgres docker compose up -d --wait api
Container mtusi-lab2-clean-api-1 Healthy
Container mtusi-lab2-clean-api-1 Recreated
Container mtusi-lab2-clean-postgres-1 Healthy
Container mtusi-lab2-clean-valkey-1 Healthy
api env SESSION_STORE=postgres
containers BEFORE:
api StartedAt=2026-10-12T17:10:11.785377847Z
postgres StartedAt=2026-10-12T17:09:31.655693328Z
valkey StartedAt=2026-10-12T17:09:31.612351204Z
$ python tests/resilience.py --mode persistence --action-script scripts/restart.cmd
Executing explicit persistence hook; hook output suppressed to avoid leaking secrets.
PASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence.
containers AFTER:
api StartedAt=2026-10-12T17:10:30.772464788Z
postgres StartedAt=2026-10-12T17:10:23.581636896Z
valkey StartedAt=2026-10-12T17:10:23.504892649Z
sessions rows in PostgreSQL: 3
$ docker compose up -d --wait api # back to the default SESSION_STORE=valkey
Container mtusi-lab2-clean-api-1 Healthy
Container mtusi-lab2-clean-postgres-1 Healthy
Container mtusi-lab2-clean-valkey-1 Healthy
api env SESSION_STORE=valkey
+14
View File
@@ -0,0 +1,14 @@
# make test-persistence ACTION_SCRIPT=scripts/restart.sh (Windows: scripts/restart.cmd runs the same restart.sh via Git Bash)
containers BEFORE:
api StartedAt=2026-10-12T17:09:00.366421789Z
postgres StartedAt=2026-10-12T17:08:53.162313311Z
valkey StartedAt=2026-10-12T17:08:53.503522499Z
$ python tests/resilience.py --mode persistence --action-script scripts/restart.cmd --base-url http://127.0.0.1:8081
Executing explicit persistence hook; hook output suppressed to avoid leaking secrets.
PASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence.
containers AFTER (all three restarted, volumes kept):
api StartedAt=2026-10-12T17:09:38.831312693Z
postgres StartedAt=2026-10-12T17:09:31.655693328Z
valkey StartedAt=2026-10-12T17:09:31.612351204Z
mtusi-lab2-clean_pgdata
mtusi-lab2-clean_valkeydata
+5
View File
@@ -0,0 +1,5 @@
variant,rows,table_bytes,pkey_bytes,secondary_index_bytes,secondary_bytes_per_row,index_build_seconds
keyset_index,121120,35037184,4808704,7159808,59.1,0.3
chat_id_index,121120,35037184,4808704,876544,7.2,0.3
no_index,121120,35037184,4808704,0,0.0,0.0
keyset_plus_sender,121120,35037184,4808704,10240000,84.5,0.59
1 variant rows table_bytes pkey_bytes secondary_index_bytes secondary_bytes_per_row index_build_seconds
2 keyset_index 121120 35037184 4808704 7159808 59.1 0.3
3 chat_id_index 121120 35037184 4808704 876544 7.2 0.3
4 no_index 121120 35037184 4808704 0 0.0 0.0
5 keyset_plus_sender 121120 35037184 4808704 10240000 84.5 0.59
+6 -4
View File
@@ -27,8 +27,10 @@
TPS и задержка — медиана 5 повторов по 10 с, 8 клиентов. WAL — медиана 3 детерминированных прогонов: 5 000 транзакций, 1 клиент, autovacuum выключен, CHECKPOINT перед прогоном.
| Индексы messages | TPS (min–max) | p50, мс | p95, мс | p99, мс | WAL, байт/вставку (min–max) | Размер индексов, МиБ |
| Индексы messages | TPS (min–max) | p50, мс | p95, мс | p99, мс | WAL, байт/вставку (min–max) | Доп. индексы на 121 120 строк, МиБ |
| --- | ---: | ---: | ---: | ---: | ---: | ---: |
| no_index | 1 954 (1 540–2 055) | 3.55 | 7.14 | 12.2 | 1930 (1884–1940) | 4.6 |
| keyset_index | 1 577 (1 002–1 630) | 4.73 | 8.50 | 13.0 | 2910 (2800–2926) | 24.0 |
| keyset_plus_sender | 1 223 (896–1 607) | 6.25 | 9.30 | 13.9 | 3318 (3310–3414) | 46.6 |
| no_index | 1 954 (1 540–2 055) | 3.55 | 7.14 | 12.2 | 1930 (1884–1940) | 0.0 |
| keyset_index | 1 577 (1 002–1 630) | 4.73 | 8.50 | 13.0 | 2910 (2800–2926) | 6.8 |
| keyset_plus_sender | 1 223 (896–1 607) | 6.25 | 9.30 | 13.9 | 3318 (3310–3414) | 9.8 |
Размеры индексов измерены отдельно на одинаковых 121 120 строках (bench/track2/index_sizes.py); первичный ключ во всех вариантах — 4.6 МиБ, таблица — 33.4 МиБ.