ЛР 2: исследовать и ограничить cache stampede — на 5
Student application / application (pull_request) Canceled after 0s
Skeleton contracts / contracts (pull_request) Canceled after 0s

This commit is contained in:
2026-10-25 15:42:14 +03:00
parent b5b35682c2
commit 799f56c513
116 changed files with 76270 additions and 91 deletions
@@ -0,0 +1,10 @@
time="2026-10-25T02:06:10+03:00" level=warning msg="Found orphan containers ([lab2-g5-final-measure]) for this project. If you removed or renamed this service in your compose file, you can run this command with the --remove-orphans flag to clean it up."
Container lab2-g5-20261025-final-api-run-cfeaa36dba5c Creating
Container lab2-g5-20261025-final-api-run-cfeaa36dba5c Created
PASS: cold/warm/real TTL expiry; 10 empty/malformed/wrong-id/wrong-type/extra-field values repaired from PG
PASS: member/path/cursor UUID semantics; duplicate aliases 400; malformed timestamps 400; outsider+bad cursor 404; unknown route envelope
PASS: chats/chat lists/messages read-after-write immediately across two API processes in both directions
PASS: revoked/expired sessions 401 in warm/cold/corrupt cache and in another API process
PASS: HTTP C8 lock=0.2s processes=2 real profile SELECT=2 elapsed=0.243s max_http=0.234s
PASS: HTTP C8 lock=1.2s processes=1 real profile SELECT=8 elapsed=1.246s max_http=1.232s
PASS: grade5 additional integration checks completed
@@ -0,0 +1,6 @@
time="2026-10-25T02:06:55+03:00" level=warning msg="Found orphan containers ([lab2-g5-final-measure]) for this project. If you removed or renamed this service in your compose file, you can run this command with the --remove-orphans flag to clean it up."
Container lab2-g5-20261025-final-tools-run-1b69563af0d5 Creating
Container lab2-g5-20261025-final-tools-run-1b69563af0d5 Created
PASS: Valkey down: valid user/read-after-write work, expired/revoked/anonymous 401, errors omit input; 0.543s
PASS: own profile lost before actual Valkey restart; refill from PG after cooldown, TTL<=60, expired/revoked stay401; recovery 7.725s
PASS: API/PG/Valkey logs contain no test message marker, five passwords/tokens or Argon2 hashes; cache only public User fields. This is a tested marker scope, not a universal proof.
+4
View File
@@ -0,0 +1,4 @@
python3 scripts/check_contract.py
PASS: offline skeleton structure, local refs and Python syntax; application NOT tested.
python3 scripts/validate_openapi.py
PASS: full OpenAPI 3.1 and JSON Schema validation; application NOT tested.
+7
View File
@@ -0,0 +1,7 @@
PASS: concurrent same username: 12 requests, 1 x 201, 11 x 409
PASS: unknown member FK after parent INSERT rolls back chat and memberships; duplicate/missing owner -> 400
PASS: NUL in display_name/title/text -> 400; PostgreSQL readiness remains 200
PASS: strict types/extra fields, malformed JSON, UUID, limits/cursors, blank/oversized text, outsider isolation
PASS: 40 concurrent writes; tied timestamp UUID ordering; complete keyset traversal, scoped cursors, changing limit, read-after-write
PASS: malformed Basic, wrong/unknown credentials uniform 401, X-User-Id ignored, 128-code-point UTF8 colon password, stored Argon2id
PASS: real Valkey GET hits, TTL <=60 without sliding; expiry/refill; logout rejects cached profile and repeated logout
+1
View File
@@ -0,0 +1 @@
PASS: SESSION_TTL_SECONDS=2: immediate authentication succeeds; after 2.21s cached profile cannot bypass expiry/logout
+33
View File
@@ -0,0 +1,33 @@
Rows in test chat: 10000
Position: 0
Limit (cost=0.29..4.17 rows=51 width=70) (actual time=0.016..0.064 rows=51 loops=1)
Buffers: shared hit=3
-> Index Scan using messages_history on messages (cost=0.29..762.53 rows=10000 width=70) (actual time=0.015..0.030 rows=51 loops=1)
Index Cond: (chat_id = '75f21d02-9989-494a-9028-54436d4d64c8'::uuid)
Buffers: shared hit=3
Planning:
Buffers: shared hit=18
Planning Time: 0.388 ms
Execution Time: 0.157 ms
Position: 5000
Limit (cost=0.29..5.44 rows=51 width=70) (actual time=0.015..0.036 rows=51 loops=1)
Buffers: shared hit=4
-> Index Scan using messages_history on messages (cost=0.29..503.80 rows=4981 width=70) (actual time=0.014..0.029 rows=51 loops=1)
Index Cond: ((chat_id = '75f21d02-9989-494a-9028-54436d4d64c8'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.005001+00'::timestamp with time zone, '3bf71f4a-89cf-43ad-b422-ffe236dc1f2c'::uuid)))
Buffers: shared hit=4
Planning Time: 0.109 ms
Execution Time: 0.135 ms
Position: 9900
Limit (cost=0.29..68.56 rows=51 width=70) (actual time=0.028..0.046 rows=51 loops=1)
Buffers: shared hit=3
-> Index Scan using messages_history on messages (cost=0.29..135.50 rows=101 width=70) (actual time=0.027..0.038 rows=51 loops=1)
Index Cond: ((chat_id = '75f21d02-9989-494a-9028-54436d4d64c8'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.009901+00'::timestamp with time zone, 'afbc2087-9faa-444d-b4f8-a2e8e1f28fe0'::uuid)))
Buffers: shared hit=3
Planning Time: 0.178 ms
Execution Time: 0.085 ms
PostgreSQL: 16.8 (Debian 16.8-1.pgdg120+1)
Durability: on on
PASS: actual EXPLAIN ANALYZE BUFFERS at first/middle/tail; API traversal 10000 rows, 100 pages, 2.597s
+4
View File
@@ -0,0 +1,4 @@
PASS: Valkey stopped: ready=200, authenticated read/write via PG, unknown/missing/revoked=401, outsider=404; scenario 0.363s
PASS: PostgreSQL stopped: ready/auth/write=503, live=200, no credentials=401, no cached authentication; scenario 0.153s
PASS: PostgreSQL recovery 2.083s, same valid token/data survive, revoked token remains revoked, rejected write absent
PASS: all 22 HTTP requests bounded below 4.5s; maximum 0.451s
+3
View File
@@ -0,0 +1,3 @@
PASS: versioned migrations applied (already applied versions skipped)
PASS: versioned migrations applied (already applied versions skipped)
PASS: two repeated migrations; all table counts and absolute session expiries unchanged: {'users': 10, 'chats': 3, 'chat_members': 5, 'messages': 43, 'sessions': 7, 'schema_migrations': 1}
+9
View File
@@ -0,0 +1,9 @@
/lab2-g5-20261025-final-api-1 2026-10-24T23:02:50.740678331Z sha256:0bed5b677a58a94af1d5adb000f667310242521eac8377202d1ff35634e1c3f8
/lab2-g5-20261025-final-postgres-1 2026-10-24T23:05:19.222264359Z sha256:301bcb60b8a3ee4ab7e147932723e3abd1cef53516ce5210b39fd9fe5e3602ae
/lab2-g5-20261025-final-valkey-1 2026-10-24T23:05:17.117404887Z sha256:752ba000a58bc8925d11ee863a39b5225617cd2cb3dbc9ec8ac65268b65ebb6d
python3 tests/resilience.py --mode persistence --action-script "scripts/restart.sh" --base-url "http://api: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.
/lab2-g5-20261025-final-api-1 2026-10-24T23:05:25.466506921Z sha256:0bed5b677a58a94af1d5adb000f667310242521eac8377202d1ff35634e1c3f8
/lab2-g5-20261025-final-postgres-1 2026-10-24T23:05:25.190802943Z sha256:301bcb60b8a3ee4ab7e147932723e3abd1cef53516ce5210b39fd9fe5e3602ae
/lab2-g5-20261025-final-valkey-1 2026-10-24T23:05:25.183415205Z sha256:752ba000a58bc8925d11ee863a39b5225617cd2cb3dbc9ec8ac65268b65ebb6d
@@ -0,0 +1 @@
PASS: same opaque token authenticates after all services restart; absolute PG expires_at unchanged; only 32-byte token hash stored
+2
View File
@@ -0,0 +1,2 @@
python3 tests/smoke.py --base-url "http://api:8080"
PASS: lab2 public API scenario; infrastructure and grading evidence remain separate.
+13
View File
@@ -0,0 +1,13 @@
time="2026-10-25T02:06:02+03:00" level=warning msg="Found orphan containers ([lab2-g5-final-measure]) for this project. If you removed or renamed this service in your compose file, you can run this command with the --remove-orphans flag to clean it up."
Container lab2-g5-20261025-final-api-run-9ee0b977d673 Creating
Container lab2-g5-20261025-final-api-run-9ee0b977d673 Created
test_different_users_do_not_serialize (__main__.SingleFlightTests.test_different_users_do_not_serialize) ... ok
test_leader_exception_wakes_waiters_and_retry (__main__.SingleFlightTests.test_leader_exception_wakes_waiters_and_retry) ... ok
test_registry_limit_direct_fallback (__main__.SingleFlightTests.test_registry_limit_direct_fallback) ... ok
test_same_user_one_load (__main__.SingleFlightTests.test_same_user_one_load) ... ok
test_wait_timeout_fallback_does_not_replace_leader (__main__.SingleFlightTests.test_wait_timeout_fallback_does_not_replace_leader) ... ok
----------------------------------------------------------------------
Ran 5 tests in 0.330s
OK