Лабораторная работа 2

This commit is contained in:
2026-10-22 13:47:47 +03:00
parent 65003b6119
commit 43daf18d04
38 changed files with 2952 additions and 25 deletions
+4
View File
@@ -0,0 +1,4 @@
$ make check
PASS: offline skeleton structure, local refs and Python syntax; application NOT tested.
$ make validate
PASS: full OpenAPI 3.1 and JSON Schema validation; application NOT tested.
+117
View File
@@ -0,0 +1,117 @@
{
"base_url": "http://127.0.0.1:8080",
"timings": {
"redis_down_first_request_s": 0.0,
"redis_down_max_write_s": 0.031,
"postgres_down_write_s": 3.0,
"postgres_recovery_s": 0.02
},
"checks": [
{
"check": "redis down: existing token still valid via PostgreSQL",
"ok": true,
"detail": "0.000s"
},
{
"check": "redis down: writes succeed",
"ok": true,
"detail": ""
},
{
"check": "redis down: bounded latency",
"ok": true,
"detail": "max 0.031s over 10 requests"
},
{
"check": "redis down: readiness stays 200 (cache is not critical)",
"ok": true,
"detail": ""
},
{
"check": "redis down: login works",
"ok": true,
"detail": ""
},
{
"check": "redis down: logout works",
"ok": true,
"detail": ""
},
{
"check": "redis down: revoked token rejected",
"ok": true,
"detail": ""
},
{
"check": "redis down: anonymous rejected",
"ok": true,
"detail": ""
},
{
"check": "redis down: unknown token rejected",
"ok": true,
"detail": ""
},
{
"check": "redis back: requests ok",
"ok": true,
"detail": ""
},
{
"check": "postgres down: liveness 200",
"ok": true,
"detail": ""
},
{
"check": "postgres down: readiness 503 unavailable",
"ok": true,
"detail": "3.000s"
},
{
"check": "postgres down: anonymous -> 401 (not trusted)",
"ok": true,
"detail": "status 401"
},
{
"check": "postgres down: unknown token is not accepted (503)",
"ok": true,
"detail": "status 503, 3.000s"
},
{
"check": "postgres down: write -> 503 within bound",
"ok": true,
"detail": "status 503, 3.000s"
},
{
"check": "postgres down: history read -> 503",
"ok": true,
"detail": "status 503"
},
{
"check": "postgres down: login -> 503 (not 401, not 201)",
"ok": true,
"detail": "status 503"
},
{
"check": "postgres down: error hides internals",
"ok": true,
"detail": ""
},
{
"check": "postgres back: readiness recovered",
"ok": true,
"detail": "0.0s"
},
{
"check": "postgres back: same token reads intact history",
"ok": true,
"detail": ""
},
{
"check": "postgres back: rejected write was not stored",
"ok": true,
"detail": ""
}
],
"passed": true
}
Binary file not shown.
+17
View File
@@ -0,0 +1,17 @@
{
"lab": 2,
"workload": "closed-loop POST messages; no automatic retries",
"requested_duration_seconds": 30.0,
"elapsed_seconds": 30.096,
"concurrency": 4,
"successful_requests": 9842,
"failed_requests": 0,
"error_ratio": 0.0,
"successful_rps": 327.024,
"successful_latency_ms": {
"p50": 11.831,
"p95": 17.414,
"p99": 20.949
},
"note": "Latency percentiles cover successes only. Timeouts/errors are counted separately; closed-loop has coordinated omission and client overhead."
}
+3
View File
@@ -0,0 +1,3 @@
$ make test-persistence ACTION_SCRIPT=<restart hook>
Executing explicit persistence hook; hook output suppressed to avoid leaking secrets.
PASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence.
+3
View File
@@ -0,0 +1,3 @@
# Локальный стенд без Docker (PID процессов до/после restart hook; volumes = каталоги данных сохраняются)
before: postgres=1212 redis=1222 api=1228 users_in_db=51 sessions_in_db=42
after: postgres=1269 redis=1279 api=1286 users_in_db=51 sessions_in_db=42
+2
View File
@@ -0,0 +1,2 @@
$ make test BASE_URL=http://127.0.0.1:8080
PASS: lab2 public API scenario; infrastructure and grading evidence remain separate.
+42
View File
@@ -0,0 +1,42 @@
$ python student-tests/run_all.py --base-url http://127.0.0.1:8080 --expiry-url http://127.0.0.1:8081
== API, auth, concurrency, rollback, expiry tests
test_chat_list_pagination (test_api.ApiBehaviorTests.test_chat_list_pagination) ... ok
test_cursor_from_other_chat_returns_400 (test_api.ApiBehaviorTests.test_cursor_from_other_chat_returns_400) ... ok
test_duplicate_username_returns_409 (test_api.ApiBehaviorTests.test_duplicate_username_returns_409) ... ok
test_empty_message_returns_400 (test_api.ApiBehaviorTests.test_empty_message_returns_400) ... ok
test_malformed_json_returns_400 (test_api.ApiBehaviorTests.test_malformed_json_returns_400) ... ok
test_naive_timestamp_cursor_returns_400 (test_api.ApiBehaviorTests.test_naive_timestamp_cursor_returns_400) ... ok
test_outsider_cannot_access_chat (test_api.ApiBehaviorTests.test_outsider_cannot_access_chat) ... ok
test_pagination_returns_all_messages_without_duplicates (test_api.ApiBehaviorTests.test_pagination_returns_all_messages_without_duplicates) ... ok
test_password_never_returned (test_api.ApiBehaviorTests.test_password_never_returned) ... ok
test_registration_without_password_returns_400 (test_api.ApiBehaviorTests.test_registration_without_password_returns_400) ... ok
test_sender_id_in_body_rejected (test_api.ApiBehaviorTests.test_sender_id_in_body_rejected) ... ok
test_short_password_returns_400 (test_api.ApiBehaviorTests.test_short_password_returns_400) ... ok
test_basic_on_business_endpoint_rejected (test_auth.AuthTests.test_basic_on_business_endpoint_rejected) ... ok
test_logout_revokes_only_current_session (test_auth.AuthTests.test_logout_revokes_only_current_session) ... ok
test_malformed_basic_headers (test_auth.AuthTests.test_malformed_basic_headers) ... ok
test_password_with_colon_and_unicode (test_auth.AuthTests.test_password_with_colon_and_unicode) ... ok
test_session_shape_and_token_entropy (test_auth.AuthTests.test_session_shape_and_token_entropy) ... ok
test_unknown_and_garbage_tokens (test_auth.AuthTests.test_unknown_and_garbage_tokens) ... ok
test_wrong_password_and_unknown_user_look_the_same (test_auth.AuthTests.test_wrong_password_and_unknown_user_look_the_same) ... ok
test_x_user_id_gives_no_access (test_auth.AuthTests.test_x_user_id_gives_no_access) ... ok
test_duplicate_and_missing_caller_rejected (test_concurrency.ChatRollbackTests.test_duplicate_and_missing_caller_rejected) ... ok
test_unknown_member_rolls_back_whole_chat (test_concurrency.ChatRollbackTests.test_unknown_member_rolls_back_whole_chat)
Чат вставляется первым, затем участники по порядку (сначала сам владелец). ... ok
test_same_username_parallel_registration (test_concurrency.RegistrationRaceTests.test_same_username_parallel_registration) ... ok
test_session_expires_even_when_cached (test_expiry.ExpiryTests.test_session_expires_even_when_cached) ... ok
test_failure_after_inserts_leaves_nothing (test_storage_rollback.StorageRollbackTests.test_failure_after_inserts_leaves_nothing) ... ok
test_migrations_are_idempotent (test_storage_rollback.StorageRollbackTests.test_migrations_are_idempotent) ... ok
test_no_orphan_chats_in_database (test_storage_rollback.StorageRollbackTests.test_no_orphan_chats_in_database) ... ok
test_passwords_stored_as_argon2id (test_storage_rollback.StorageRollbackTests.test_passwords_stored_as_argon2id) ... ok
----------------------------------------------------------------------
Ran 28 tests in 6.224s
OK
== Concurrent write test
PASS: concurrent write test; 10 clients x 10 messages = 100 messages; no lost or duplicate messages
ALL STUDENT TESTS PASSED