ЛР2: PostgreSQL, сессии и Valkey на оценку 4

This commit is contained in:
gera
2026-10-16 00:50:33 +03:00
parent 65003b6119
commit f612fbef77
32 changed files with 2339 additions and 21 deletions
+16
View File
@@ -0,0 +1,16 @@
./scripts/test-deps-down.sh
=== stop valkey (cache bypass) ===
Container mtusi2026lab2-valkey-1 Stopping
Container mtusi2026lab2-valkey-1 Stopped
with valkey down /users/me -> 200 (expect 200)
=== start valkey, stop postgres ===
Container mtusi2026lab2-valkey-1 Starting
Container mtusi2026lab2-valkey-1 Started
Container mtusi2026lab2-postgres-1 Stopping
Container mtusi2026lab2-postgres-1 Stopped
postgres down ready=503 me=503 (expect 503/503)
=== restore postgres ===
Container mtusi2026lab2-postgres-1 Starting
Container mtusi2026lab2-postgres-1 Started
restored /users/me -> 200 (expect 200)
PASS: dependency failures
+15
View File
@@ -0,0 +1,15 @@
./scripts/test-expiry.sh
=== restart api with SESSION_TTL_SECONDS=2 ===
Container mtusi2026lab2-api-1 Recreate
Container mtusi2026lab2-api-1 Recreated
Container mtusi2026lab2-api-1 Starting
Container mtusi2026lab2-api-1 Started
immediate /users/me -> 200 (expect 200)
sleep 3 for expiry
after ttl /users/me -> 401 (expect 401)
=== restore SESSION_TTL_SECONDS=3600 ===
Container mtusi2026lab2-api-1 Recreate
Container mtusi2026lab2-api-1 Recreated
Container mtusi2026lab2-api-1 Starting
Container mtusi2026lab2-api-1 Started
PASS: session expiry
+49
View File
@@ -0,0 +1,49 @@
date=2026-10-15T21:41:08Z
chat_id=a9b8867c-4828-4847-ab1d-39f3cd4dcdbb
count=10001
=== keyset with index messages_history_idx ===
QUERY PLAN
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Limit (cost=46.77..46.81 rows=14 width=88) (actual time=3.557..3.567 rows=50 loops=1)
Buffers: shared hit=258
-> Sort (cost=46.77..46.81 rows=14 width=88) (actual time=3.556..3.560 rows=50 loops=1)
Sort Key: created_at, id
Sort Method: top-N heapsort Memory: 31kB
Buffers: shared hit=258
-> Bitmap Heap Scan on messages (cost=4.43..46.50 rows=14 width=88) (actual time=1.233..2.307 rows=10001 loops=1)
Recheck Cond: ((chat_id = 'a9b8867c-4828-4847-ab1d-39f3cd4dcdbb'::uuid) AND (ROW(created_at, id) > ROW('1970-01-01 00:00:00+00'::timestamp with time zone, '00000000-0000-4000-8000-000000000000'::uuid)))
Heap Blocks: exact=123
Buffers: shared hit=252
-> Bitmap Index Scan on messages_history_idx (cost=0.00..4.42 rows=14 width=0) (actual time=1.194..1.195 rows=10001 loops=1)
Index Cond: ((chat_id = 'a9b8867c-4828-4847-ab1d-39f3cd4dcdbb'::uuid) AND (ROW(created_at, id) > ROW('1970-01-01 00:00:00+00'::timestamp with time zone, '00000000-0000-4000-8000-000000000000'::uuid)))
Buffers: shared hit=129
Planning:
Buffers: shared hit=101
Planning Time: 1.515 ms
Execution Time: 3.739 ms
(17 rows)
=== OFFSET page ~200 (full scan risk) ===
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------------------
Limit (cost=93.55..93.55 rows=1 width=88) (actual time=5.617..5.627 rows=50 loops=1)
Buffers: shared hit=258
-> Sort (cost=93.44..93.55 rows=43 width=88) (actual time=5.054..5.347 rows=5050 loops=1)
Sort Key: created_at, id
Sort Method: quicksort Memory: 1713kB
Buffers: shared hit=258
-> Bitmap Heap Scan on messages (cost=4.62..92.28 rows=43 width=88) (actual time=0.847..2.033 rows=10001 loops=1)
Recheck Cond: (chat_id = 'a9b8867c-4828-4847-ab1d-39f3cd4dcdbb'::uuid)
Heap Blocks: exact=123
Buffers: shared hit=252
-> Bitmap Index Scan on messages_history_idx (cost=0.00..4.61 rows=43 width=0) (actual time=0.818..0.818 rows=10001 loops=1)
Index Cond: (chat_id = 'a9b8867c-4828-4847-ab1d-39f3cd4dcdbb'::uuid)
Buffers: shared hit=129
Planning:
Buffers: shared hit=102
Planning Time: 1.926 ms
Execution Time: 5.951 ms
(17 rows)
+16
View File
@@ -0,0 +1,16 @@
BASE_URL="http://localhost:8080" python3 tests/test_own.py -v
test_bad_json (__main__.OwnTests.test_bad_json) ... ok
test_basic_on_business (__main__.OwnTests.test_basic_on_business) ... ok
test_cursor_other_chat (__main__.OwnTests.test_cursor_other_chat) ... ok
test_duplicate_username (__main__.OwnTests.test_duplicate_username) ... ok
test_empty_message (__main__.OwnTests.test_empty_message) ... ok
test_foreign_chat (__main__.OwnTests.test_foreign_chat) ... ok
test_logout (__main__.OwnTests.test_logout) ... ok
test_pagination_pages (__main__.OwnTests.test_pagination_pages) ... ok
test_wrong_password (__main__.OwnTests.test_wrong_password) ... ok
test_x_user_id_ignored (__main__.OwnTests.test_x_user_id_ignored) ... ok
----------------------------------------------------------------------
Ran 10 tests in 4.147s
OK
+22
View File
@@ -0,0 +1,22 @@
date=2026-10-15T21:41:21Z
=== before restart ===
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
mtusi2026lab2-api-1 mtusi-messenger:lab2 "/app/messenger" api 21 seconds ago Up 20 seconds (healthy) 127.0.0.1:8080->8080/tcp
mtusi2026lab2-postgres-1 postgres:17-alpine@sha256:b0f9560a2de083e2cc7382e75f808c7381a32852a7ec49117deedb300e552b24 "docker-entrypoint.s…" postgres 2 minutes ago Up 15 seconds (healthy) 5432/tcp
mtusi2026lab2-valkey-1 valkey/valkey:8.1-alpine@sha256:081c2f5cb575efc901aa80ff9cdbd1ec6a301682fd35e1ebb4b0990a4a4a8507 "tini -- docker-entr…" valkey 2 minutes ago Up 17 seconds (healthy) 6379/tcp
=== StartedAt before ===
/mtusi2026lab2-api-1 2026-10-15T21:41:01.004288114Z
/mtusi2026lab2-postgres-1 2026-10-15T21:41:06.039417376Z
/mtusi2026lab2-valkey-1 2026-10-15T21:41:04.187505543Z
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.
=== after restart ===
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
mtusi2026lab2-api-1 mtusi-messenger:lab2 "/app/messenger" api 29 seconds ago Up Less than a second (health: starting) 127.0.0.1:8080->8080/tcp
mtusi2026lab2-postgres-1 postgres:17-alpine@sha256:b0f9560a2de083e2cc7382e75f808c7381a32852a7ec49117deedb300e552b24 "docker-entrypoint.s…" postgres 3 minutes ago Up 5 seconds (healthy) 5432/tcp
mtusi2026lab2-valkey-1 valkey/valkey:8.1-alpine@sha256:081c2f5cb575efc901aa80ff9cdbd1ec6a301682fd35e1ebb4b0990a4a4a8507 "tini -- docker-entr…" valkey 3 minutes ago Up 5 seconds (healthy) 6379/tcp
=== StartedAt after ===
/mtusi2026lab2-api-1 2026-10-15T21:41:28.660588193Z
/mtusi2026lab2-postgres-1 2026-10-15T21:41:23.448021809Z
/mtusi2026lab2-valkey-1 2026-10-15T21:41:23.246159861Z
+3
View File
@@ -0,0 +1,3 @@
BASE_URL="http://localhost:8080" python3 tests/test_race_register.py
codes=[201, 409, 409, 409, 409, 409, 409, 409, 409, 409, 409, 409, 409, 409, 409, 409, 409, 409, 409, 409] created=1 conflict=19
PASS: race register handled by unique username
+2
View File
@@ -0,0 +1,2 @@
BASE_URL="http://localhost:8080" python3 tests/test_rollback.py
PASS: unknown member rolls back chat create
+6
View File
@@ -0,0 +1,6 @@
date=2026-10-15T21:41:19Z
commit=65003b6
python3 scripts/check_contract.py
PASS: offline skeleton structure, local refs and Python syntax; application NOT tested.
python3 tests/smoke.py --base-url "http://localhost:8080"
PASS: lab2 public API scenario; infrastructure and grading evidence remain separate.