feat: ЛР5 - асинхронная обработка вложений, RabbitMQ и transactional outbox

This commit is contained in:
Ильяс
2026-11-20 17:03:59 +03:00
parent 7cfc6d40a6
commit 7d06ecf230
27 changed files with 1536 additions and 103 deletions
+2
View File
@@ -0,0 +1,2 @@
python3 scripts/check_contract.py
PASS: offline skeleton structure, local refs and Python syntax; application NOT tested.
+9
View File
@@ -0,0 +1,9 @@
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
mtusi2026lab5-api-1-1 highload-messenger:lab5 "python -m uvicorn a…" api-1 2 minutes ago Up 2 minutes (healthy) 8080/tcp
mtusi2026lab5-api-2-1 highload-messenger:lab5 "python -m uvicorn a…" api-2 2 minutes ago Up 2 minutes (healthy) 8080/tcp
mtusi2026lab5-broker-1 rabbitmq:3.13-alpine "docker-entrypoint.s…" broker 2 minutes ago Up 2 minutes (healthy) 4369/tcp, 5671-5672/tcp, 15691-15692/tcp, 25672/tcp
mtusi2026lab5-load_balancer-1 nginx:1.27-alpine "/docker-entrypoint.…" load_balancer 2 minutes ago Up 2 minutes (healthy) 80/tcp, 0.0.0.0:8080->8080/tcp, [::]:8080->8080/tcp
mtusi2026lab5-minio-1 cleanstart/minio:0.20260330.001845 "/usr/bin/minio serv…" minio 2 minutes ago Up 2 minutes (healthy)
mtusi2026lab5-postgres-1 postgres:16-alpine "docker-entrypoint.s…" postgres 2 minutes ago Up 2 minutes (healthy) 5432/tcp
mtusi2026lab5-redis-1 redis:7-alpine "docker-entrypoint.s…" redis 2 minutes ago Up 2 minutes (healthy) 6379/tcp
mtusi2026lab5-worker-1 highload-messenger:lab5 "python -m app.worker" worker 2 minutes ago Up 2 minutes (healthy) 8080/tcp
+4
View File
@@ -0,0 +1,4 @@
python3 tests/resilience.py --mode failover --action-script "scripts/stop-one.sh" --base-url "http://localhost:8080"
Executing explicit failover hook; hook output suppressed to avoid leaking secrets.
{"observed_instances_before": 2, "successful_writes": 116, "failed_attempts": 0, "first_recovery_seconds": 0.87}
PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
+17
View File
@@ -0,0 +1,17 @@
{
"lab": 5,
"workload": "closed-loop POST messages; no automatic retries",
"requested_duration_seconds": 15.0,
"elapsed_seconds": 15.007,
"concurrency": 4,
"successful_requests": 4773,
"failed_requests": 0,
"error_ratio": 0.0,
"successful_rps": 318.051,
"successful_latency_ms": {
"p50": 6.603,
"p95": 59.542,
"p99": 80.594
},
"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 @@
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.
+10
View File
@@ -0,0 +1,10 @@
x-instance-id: api-2
x-instance-id: api-1
x-instance-id: api-2
x-instance-id: api-1
x-instance-id: api-2
x-instance-id: api-1
x-instance-id: api-2
x-instance-id: api-1
x-instance-id: api-2
x-instance-id: api-1
+2
View File
@@ -0,0 +1,2 @@
python3 tests/smoke.py --base-url "http://localhost:8080"
PASS: lab5 public API scenario; infrastructure and grading evidence remain separate.
+51
View File
@@ -0,0 +1,51 @@
BASE_URL="http://localhost:8080" .venv/bin/pytest tests_student/ -v
/home/ilyas/projects/labs_highload/mtusi2026lab5/.venv/lib/python3.15/site-packages/pytest_asyncio/plugin.py:300: PytestDeprecationWarning: The configuration option "asyncio_default_fixture_loop_scope" is unset.
The event loop scope for asynchronous fixtures will default to the "fixture" caching scope. Future versions of pytest-asyncio will default the loop scope for asynchronous fixtures to "function" scope. Set the default fixture loop scope explicitly in order to avoid unexpected behavior in the future. Valid fixture loop scopes are: "function", "class", "module", "package", "session"
warnings.warn(PytestDeprecationWarning(_DEFAULT_FIXTURE_LOOP_SCOPE_UNSET))
============================= test session starts ==============================
platform linux -- Python 3.15.2, pytest-9.2.0, pluggy-1.7.0 -- /home/ilyas/projects/labs_highload/mtusi2026lab5/.venv/bin/python3
cachedir: .pytest_cache
rootdir: /home/ilyas/projects/labs_highload/mtusi2026lab5
configfile: pytest.ini
plugins: anyio-4.16.0, asyncio-1.4.1.post1
asyncio: mode=Mode.AUTO, debug=False, asyncio_default_fixture_loop_scope=None, asyncio_default_test_loop_scope=function
collecting ... ␍collected 35 items
tests_student/tests.py::test_invalid_json_and_extra_fields PASSED [ 2%]
tests_student/tests.py::test_outsider_chat_access_is_404 PASSED [ 5%]
tests_student/tests.py::test_empty_and_whitespace_message PASSED [ 8%]
tests_student/tests.py::test_duplicate_username_conflict PASSED [ 11%]
tests_student/tests.py::test_wrong_password_and_bad_basic_auth PASSED [ 14%]
tests_student/tests.py::test_logout_and_revocation PASSED [ 17%]
tests_student/tests.py::test_multi_page_cursor_pagination PASSED [ 20%]
tests_student/tests.py::test_concurrency_race_condition PASSED [ 22%]
tests_student/tests.py::test_password_whitespace_rejected PASSED [ 25%]
tests_student/tests.py::test_auth_sessions_with_body_rejected PASSED [ 28%]
tests_student/tests.py::test_unsupported_media_type_415 PASSED [ 31%]
tests_student/tests.py::test_nul_byte_in_strings_handled PASSED [ 34%]
tests_student/tests.py::test_basic_auth_invalid_base64_returns_401 PASSED [ 37%]
tests_student/tests.py::test_cross_chat_cursor_rejected_400 PASSED [ 40%]
tests_student/tests.py::test_utf8_password_support PASSED [ 42%]
tests_student/tests.py::test_health_readiness_and_liveness PASSED [ 45%]
tests_student/tests.py::test_instance_id_header_present PASSED [ 48%]
tests_student/tests.py::test_idempotency_key_validation PASSED [ 51%]
tests_student/tests.py::test_idempotency_replay_and_conflict PASSED [ 54%]
tests_student/tests.py::test_idempotency_acl_check_on_replay PASSED [ 57%]
tests_student/tests.py::test_invalid_cursor_date_returns_400 PASSED [ 60%]
tests_student/tests.py::test_strict_types_and_json_parsing PASSED [ 62%]
tests_student/tests.py::test_chat_creation_with_unknown_participant_is_400 PASSED [ 65%]
tests_student/tests.py::test_password_with_colons_and_utf8 PASSED [ 68%]
tests_student/tests.py::test_keyset_pagination_returns_next_cursor PASSED [ 71%]
tests_student/tests.py::test_attachment_upload_and_download_flow PASSED [ 74%]
tests_student/tests.py::test_attachment_unsupported_media_type_and_magic_bytes PASSED [ 77%]
tests_student/tests.py::test_attachment_filename_validation PASSED [ 80%]
tests_student/tests.py::test_attachment_payload_too_large_and_pixel_bomb PASSED [ 82%]
tests_student/tests.py::test_attachment_acl_and_isolation PASSED [ 85%]
tests_student/tests.py::test_message_linking_attachments PASSED [ 88%]
tests_student/tests.py::test_message_linking_failed_attachment_rejected PASSED [ 91%]
tests_student/tests.py::test_attachment_orphan_compensation PASSED [ 94%]
tests_student/tests.py::test_private_bucket_outside_api PASSED [ 97%]
tests_student/tests.py::test_concurrent_uploads_memory_limit PASSED [100%]
============================= 35 passed in 37.84s ==============================
+2
View File
@@ -0,0 +1,2 @@
.venv/bin/python scripts/validate_openapi.py
PASS: full OpenAPI 3.1 and JSON Schema validation; application NOT tested.