forked from mtusi2026/mtusi2026lab2
выполнение лр2 на 4
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
# EXPLAIN evidence for message history pagination
|
||||
# date: 2026-10-07T14:17:55Z commit: 65003b6
|
||||
# postgres: 17.6
|
||||
# messages total: 70112, in measured chat: 20000
|
||||
|
||||
PREPARE
|
||||
PREPARE
|
||||
=== 1. WITH index messages_chat_history_idx: first page (limit 50 + 1) ===
|
||||
QUERY PLAN
|
||||
---------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
Limit (cost=0.42..8.60 rows=51 width=78) (actual time=0.014..0.019 rows=51 loops=1)
|
||||
Buffers: shared hit=4
|
||||
-> Index Scan using messages_chat_history_idx on messages (cost=0.42..3227.11 rows=20122 width=78) (actual time=0.013..0.015 rows=51 loops=1)
|
||||
Index Cond: (chat_id = '00000000-0000-4000-8000-000000000100'::uuid)
|
||||
Buffers: shared hit=4
|
||||
Planning:
|
||||
Buffers: shared hit=106
|
||||
Planning Time: 0.272 ms
|
||||
Execution Time: 0.031 ms
|
||||
(9 rows)
|
||||
|
||||
=== 2. WITH index: deep page, cursor after message #15000 of 20000 ===
|
||||
QUERY PLAN
|
||||
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
Limit (cost=0.42..55.74 rows=51 width=78) (actual time=0.012..0.017 rows=51 loops=1)
|
||||
Buffers: shared hit=4
|
||||
-> Index Scan using messages_chat_history_idx on messages (cost=0.42..1590.70 rows=1466 width=78) (actual time=0.012..0.014 rows=51 loops=1)
|
||||
Index Cond: ((chat_id = '00000000-0000-4000-8000-000000000100'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 04:10:00+00'::timestamp with time zone, '47ba2a9c-d238-4807-2008-6ea72cb0f95c'::uuid)))
|
||||
Buffers: shared hit=4
|
||||
Planning:
|
||||
Buffers: shared hit=42
|
||||
Planning Time: 0.276 ms
|
||||
Execution Time: 0.035 ms
|
||||
(9 rows)
|
||||
|
||||
BEGIN
|
||||
DROP INDEX
|
||||
=== 3. WITHOUT index: first page ===
|
||||
QUERY PLAN
|
||||
--------------------------------------------------------------------------------------------------------------------------
|
||||
Limit (cost=2487.71..2487.84 rows=51 width=78) (actual time=4.235..4.239 rows=51 loops=1)
|
||||
Buffers: shared hit=946
|
||||
-> Sort (cost=2487.71..2538.02 rows=20122 width=78) (actual time=4.234..4.236 rows=51 loops=1)
|
||||
Sort Key: created_at, id
|
||||
Sort Method: top-N heapsort Memory: 31kB
|
||||
Buffers: shared hit=946
|
||||
-> Seq Scan on messages (cost=0.00..1816.40 rows=20122 width=78) (actual time=0.011..3.325 rows=20000 loops=1)
|
||||
Filter: (chat_id = '00000000-0000-4000-8000-000000000100'::uuid)
|
||||
Rows Removed by Filter: 50112
|
||||
Buffers: shared hit=940
|
||||
Planning:
|
||||
Buffers: shared hit=16
|
||||
Planning Time: 0.098 ms
|
||||
Execution Time: 4.249 ms
|
||||
(14 rows)
|
||||
|
||||
=== 4. WITHOUT index: deep page ===
|
||||
QUERY PLAN
|
||||
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
Limit (cost=2215.87..2216.00 rows=51 width=78) (actual time=3.117..3.121 rows=51 loops=1)
|
||||
Buffers: shared hit=940
|
||||
-> Sort (cost=2215.87..2219.53 rows=1466 width=78) (actual time=3.116..3.118 rows=51 loops=1)
|
||||
Sort Key: created_at, id
|
||||
Sort Method: top-N heapsort Memory: 31kB
|
||||
Buffers: shared hit=940
|
||||
-> Seq Scan on messages (cost=0.00..2166.96 rows=1466 width=78) (actual time=0.605..2.853 rows=5000 loops=1)
|
||||
Filter: ((chat_id = '00000000-0000-4000-8000-000000000100'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 04:10:00+00'::timestamp with time zone, '47ba2a9c-d238-4807-2008-6ea72cb0f95c'::uuid)))
|
||||
Rows Removed by Filter: 65112
|
||||
Buffers: shared hit=940
|
||||
Planning Time: 0.069 ms
|
||||
Execution Time: 3.133 ms
|
||||
(12 rows)
|
||||
|
||||
ROLLBACK
|
||||
@@ -0,0 +1,20 @@
|
||||
# Fresh volume: migrations from scratch + public smoke
|
||||
# date: 2026-10-07T14:18:43Z
|
||||
$ APP_PORT=18090 docker compose -p lab2-clean up -d --wait
|
||||
Container lab2-clean-api-1 Created
|
||||
Container lab2-clean-api-1 Healthy
|
||||
Container lab2-clean-migrate-1 Created
|
||||
Container lab2-clean-migrate-1 Exited
|
||||
Container lab2-clean-postgres-1 Created
|
||||
Container lab2-clean-postgres-1 Healthy
|
||||
Container lab2-clean-valkey-1 Created
|
||||
Container lab2-clean-valkey-1 Healthy
|
||||
Network lab2-clean_default Created
|
||||
Volume "lab2-clean_pgdata" Created
|
||||
$ docker compose -p lab2-clean logs migrate
|
||||
INFO migrate: applying 0001_init
|
||||
INFO migrate: migrations up to date: 1 applied now, 0 before
|
||||
$ make test BASE_URL=http://localhost:18090
|
||||
PASS: lab2 public API scenario; infrastructure and grading evidence remain separate.
|
||||
$ docker compose -p lab2-clean run --rm migrate # second run
|
||||
INFO migrate: migrations up to date: 0 applied now, 1 before
|
||||
@@ -0,0 +1,20 @@
|
||||
# Persistence: API + PostgreSQL + Valkey restarted, volume kept, same token
|
||||
# date: 2026-10-07T14:19:03Z
|
||||
## containers BEFORE
|
||||
api 2026-10-07T14:18:25.262485419Z running restarts=0
|
||||
postgres 2026-10-07T14:18:22.306271835Z running restarts=0
|
||||
valkey 2026-10-07T14:18:21.888265501Z running restarts=0
|
||||
volume messenger-lab2_pgdata
|
||||
|
||||
$ make test-persistence ACTION_SCRIPT=scripts/restart.sh
|
||||
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 (StartedAt changed for all three)
|
||||
api 2026-10-07T14:19:08.428103009Z running restarts=0
|
||||
postgres 2026-10-07T14:19:05.240867716Z running restarts=0
|
||||
valkey 2026-10-07T14:19:05.240850591Z running restarts=0
|
||||
volume messenger-lab2_pgdata
|
||||
|
||||
$ docker compose logs migrate | tail -1
|
||||
INFO migrate: migrations up to date: 0 applied now, 1 before
|
||||
@@ -0,0 +1,5 @@
|
||||
# date: 2026-10-07T14:19:14Z
|
||||
$ make check
|
||||
PASS: offline skeleton structure, local refs and Python syntax; application NOT tested.
|
||||
$ make test
|
||||
PASS: lab2 public API scenario; infrastructure and grading evidence remain separate.
|
||||
@@ -0,0 +1,44 @@
|
||||
# date: 2026-10-07T14:19:14Z
|
||||
$ make test-student
|
||||
BASE_URL="http://localhost:18080" sh student-tests/run_all.sh
|
||||
== own_tests.py
|
||||
ok - malformed JSON -> 400 invalid_request
|
||||
ok - foreign chat access -> 404 (no leak)
|
||||
ok - empty/whitespace message text -> 400
|
||||
ok - duplicate username -> 409, original user intact
|
||||
ok - multi-page pagination traversal: 4 pages, 7 messages, no dup/loss
|
||||
ok - cursor from another chat -> 400 (cursor is bound to its resource)
|
||||
PASS: 6/6 student checks
|
||||
|
||||
== concurrency_test.py
|
||||
PASS: 100 unique messages written and read back from 10 concurrent clients
|
||||
|
||||
== auth_test.py
|
||||
ok - wrong password / unknown user -> identical 401 Basic
|
||||
ok - missing / malformed / non-Basic login -> 401
|
||||
ok - UTF-8 password containing ':' -> 201
|
||||
ok - password shorter than 12 / missing -> 400
|
||||
ok - Basic / X-User-Id / unknown token on business endpoint -> 401
|
||||
ok - logout revokes only the current token; repeat logout -> 401
|
||||
ok - session with TTL=2s is rejected after 3s (cache entry included)
|
||||
PASS: 7 checks
|
||||
|
||||
== db_integrity_test.py
|
||||
ok - 20 concurrent registrations of one username -> 1x201, 19x409, 1 row
|
||||
ok - chat with unknown member -> 400 and transaction rolled back (no orphan chat)
|
||||
ok - password stored as $argon2id$..., sessions keep only sha256(token)
|
||||
ok - migrations run twice more: schema_migrations and data unchanged (1:49)
|
||||
PASS: 4 checks
|
||||
|
||||
== dependency_test.py
|
||||
ok - Valkey caches sessions with TTL<=300s and keeps logout tombstones
|
||||
ok - Valkey stopped: ready=200, reads/writes OK, revoked token 401, 4 ms/request
|
||||
ok - PostgreSQL stopped: live=200, ready/business=503 in 0.0s total, unverified token not trusted
|
||||
ok - PostgreSQL started again: API recovers without restart, data intact
|
||||
PASS: 4 checks
|
||||
|
||||
== sigterm_test.sh
|
||||
api stopped in 0s, exit code 0 (0 = graceful, 137 = SIGKILL)
|
||||
PASS: graceful SIGTERM shutdown, api restarted
|
||||
|
||||
ALL STUDENT TESTS PASSED
|
||||
Reference in New Issue
Block a user