ЛР5: асинхронная обработка вложений (RabbitMQ + worker), transactional outbox, варианты, трек 5.1

This commit is contained in:
2026-11-20 16:57:31 +03:00
parent 276dbdad8a
commit cbaadb7636
67 changed files with 5603 additions and 20 deletions
+26
View File
@@ -0,0 +1,26 @@
== scenario 1: accept while worker stopped, resume -> ready ==
with worker stopped: status=queued (expected queued)
API restarted; work still queued (durable)
worker resumed: status=ready variants=['crop', 'optimized', 'thumbnail']
== scenario 2: COMMIT/publish gap (broker down), API restart, then broker ==
broker down: status=queued published_at='' (expected empty)
API restarted with broker still down; intent preserved in PostgreSQL
broker back: status=ready (outbox republished without new task)
== scenario 3: transient failures -> failed(retry_exhausted) -> replay ==
injected: staging object points to a missing key (transient fetch failure)
status=failed error_code=retry_exhausted (expected retry_exhausted)
explicit replay after recovery: {"replayed": 1}
after replay: status=ready variants=['crop', 'optimized', 'thumbnail']
== scenario 4: redelivery of a ready job is a no-op ==
re-queued the same job (duplicate delivery)
status=ready variants=['crop', 'optimized', 'thumbnail'] (must be unchanged)
== scenario 5: stuck processing -> lease recovery ==
marked attachment+job processing with an expired lease
watchdog requeued and finished the job: status=ready
PASS: lab5 grade-4 failure scenarios
+148
View File
@@ -0,0 +1,148 @@
{
"results": [
{
"concurrency": 1,
"size": "small",
"bytes": 922218,
"submitted": 12,
"accepted": 12,
"errors": 0,
"codes": {
"202": 12
},
"ready": 12,
"failed": 0,
"submit_seconds": 1.42,
"drain_seconds": 11.04,
"throughput_per_s": 0.96,
"p50_ready_s": 2.24,
"p95_ready_s": 9.68,
"max_queue_depth": 10,
"worker_peak_mem_mb": 89.7
},
{
"concurrency": 2,
"size": "small",
"bytes": 922218,
"submitted": 12,
"accepted": 12,
"errors": 0,
"codes": {
"202": 12
},
"ready": 12,
"failed": 0,
"submit_seconds": 0.45,
"drain_seconds": 85.08,
"throughput_per_s": 0.14,
"p50_ready_s": 81.66,
"p95_ready_s": 83.11,
"max_queue_depth": 12,
"worker_peak_mem_mb": 77.5
},
{
"concurrency": 4,
"size": "small",
"bytes": 922218,
"submitted": 12,
"accepted": 12,
"errors": 0,
"codes": {
"202": 12
},
"ready": 12,
"failed": 0,
"submit_seconds": 2.23,
"drain_seconds": 4.1,
"throughput_per_s": 1.9,
"p50_ready_s": 2.75,
"p95_ready_s": 3.23,
"max_queue_depth": 12,
"worker_peak_mem_mb": 152.5
},
{
"concurrency": 1,
"size": "large",
"bytes": 9902323,
"submitted": 12,
"accepted": 12,
"errors": 0,
"codes": {
"202": 12
},
"ready": 12,
"failed": 0,
"submit_seconds": 46.75,
"drain_seconds": 15.97,
"throughput_per_s": 0.19,
"p50_ready_s": 27.37,
"p95_ready_s": 37.37,
"max_queue_depth": 11,
"worker_peak_mem_mb": 151.6
},
{
"concurrency": 2,
"size": "large",
"bytes": 9902323,
"submitted": 12,
"accepted": 9,
"errors": 3,
"codes": {
"202": 9,
"0": 2,
"503": 1
},
"ready": 9,
"failed": 0,
"submit_seconds": 49.83,
"drain_seconds": 7.05,
"throughput_per_s": 0.16,
"p50_ready_s": 25.99,
"p95_ready_s": 48.76,
"max_queue_depth": 8,
"worker_peak_mem_mb": 168.1
},
{
"concurrency": 4,
"size": "large",
"bytes": 9902323,
"submitted": 12,
"accepted": 11,
"errors": 1,
"codes": {
"202": 11,
"0": 1
},
"ready": 6,
"failed": 0,
"submit_seconds": 45.04,
"drain_seconds": 302.74,
"throughput_per_s": 0.02,
"p50_ready_s": 37.55,
"p95_ready_s": 39.23,
"max_queue_depth": 10,
"worker_peak_mem_mb": 252.2
},
{
"concurrency": 2,
"size": "recovery",
"bytes": 1440778,
"submitted": 1,
"accepted": 1,
"errors": 0,
"codes": {
"202": 1
},
"ready": 1,
"failed": 0,
"submit_seconds": 0.1,
"drain_seconds": 2.14,
"throughput_per_s": 0.45,
"p50_ready_s": 0.62,
"p95_ready_s": 0.62,
"max_queue_depth": 0,
"worker_peak_mem_mb": 70.0
}
],
"recovered": true
}
+19
View File
@@ -0,0 +1,19 @@
{"concurrency": 1, "size": "small", "bytes": 922218, "submitted": 12, "accepted": 12, "errors": 0, "codes": {"202": 12}, "ready": 12, "failed": 0, "submit_seconds": 1.42, "drain_seconds": 11.04, "throughput_per_s": 0.96, "p50_ready_s": 2.24, "p95_ready_s": 9.68, "max_queue_depth": 10, "worker_peak_mem_mb": 89.7}
{"concurrency": 2, "size": "small", "bytes": 922218, "submitted": 12, "accepted": 12, "errors": 0, "codes": {"202": 12}, "ready": 12, "failed": 0, "submit_seconds": 0.45, "drain_seconds": 85.08, "throughput_per_s": 0.14, "p50_ready_s": 81.66, "p95_ready_s": 83.11, "max_queue_depth": 12, "worker_peak_mem_mb": 77.5}
{"concurrency": 4, "size": "small", "bytes": 922218, "submitted": 12, "accepted": 12, "errors": 0, "codes": {"202": 12}, "ready": 12, "failed": 0, "submit_seconds": 2.23, "drain_seconds": 4.1, "throughput_per_s": 1.9, "p50_ready_s": 2.75, "p95_ready_s": 3.23, "max_queue_depth": 12, "worker_peak_mem_mb": 152.5}
{"concurrency": 1, "size": "large", "bytes": 9902323, "submitted": 12, "accepted": 12, "errors": 0, "codes": {"202": 12}, "ready": 12, "failed": 0, "submit_seconds": 46.75, "drain_seconds": 15.97, "throughput_per_s": 0.19, "p50_ready_s": 27.37, "p95_ready_s": 37.37, "max_queue_depth": 11, "worker_peak_mem_mb": 151.6}
{"concurrency": 2, "size": "large", "bytes": 9902323, "submitted": 12, "accepted": 9, "errors": 3, "codes": {"202": 9, "0": 2, "503": 1}, "ready": 9, "failed": 0, "submit_seconds": 49.83, "drain_seconds": 7.05, "throughput_per_s": 0.16, "p50_ready_s": 25.99, "p95_ready_s": 48.76, "max_queue_depth": 8, "worker_peak_mem_mb": 168.1}
{"concurrency": 4, "size": "large", "bytes": 9902323, "submitted": 12, "accepted": 11, "errors": 1, "codes": {"202": 11, "0": 1}, "ready": 6, "failed": 0, "submit_seconds": 45.04, "drain_seconds": 302.74, "throughput_per_s": 0.02, "p50_ready_s": 37.55, "p95_ready_s": 39.23, "max_queue_depth": 10, "worker_peak_mem_mb": 252.2}
{"concurrency": 2, "size": "recovery", "bytes": 1440778, "submitted": 1, "accepted": 1, "errors": 0, "codes": {"202": 1}, "ready": 1, "failed": 0, "submit_seconds": 0.1, "drain_seconds": 2.14, "throughput_per_s": 0.45, "p50_ready_s": 0.62, "p95_ready_s": 0.62, "max_queue_depth": 0, "worker_peak_mem_mb": 70.0}
concurrency size bytes accepted ready p50_s p95_s maxq peakRSS_MB
1 small 922218 12 12 2.24 9.68 10 89.7
2 small 922218 12 12 81.66 83.11 12 77.5
4 small 922218 12 12 2.75 3.23 12 152.5
1 large 9902323 12 12 27.37 37.37 11 151.6
2 large 9902323 9 9 25.99 48.76 8 168.1
4 large 9902323 11 6 37.55 39.23 10 252.2
2 recovery 1440778 1 1 0.62 0.62 0 70.0
recovery after overload: OK
{"output": "evidence/lab5-overload.json", "recovered": true}
+3
View File
@@ -0,0 +1,3 @@
# Public acceptance scenario (lab5)
$ python tests/smoke.py --base-url http://127.0.0.1:8080
PASS: lab5 public API scenario; infrastructure and grading evidence remain separate.
+60
View File
@@ -0,0 +1,60 @@
# Student black-box tests (grade 4/5), one command
$ C:\IT-labs\VNP\mtusi2026lab5\.venv\Scripts\python.exe -m pytest student-tests -v
============================= test session starts =============================
platform win32 -- Python 3.11.9, pytest-8.3.4, pluggy-1.7.0 -- C:\IT-labs\VNP\mtusi2026lab5\.venv\Scripts\python.exe
cachedir: .pytest_cache
rootdir: C:\IT-labs\VNP\mtusi2026lab5
plugins: anyio-4.16.0
collecting ... collected 49 items
student-tests/test_attachments.py::test_upload_is_202_queued_then_ready PASSED [ 2%]
student-tests/test_attachments.py::test_content_409_while_queued PASSED [ 4%]
student-tests/test_attachments.py::test_foreign_actor_gets_404 PASSED [ 6%]
student-tests/test_attachments.py::test_cross_chat_attachment_is_404 PASSED [ 8%]
student-tests/test_attachments.py::test_oversized_upload_is_413 PASSED [ 10%]
student-tests/test_attachments.py::test_corrupt_image_is_415 PASSED [ 12%]
student-tests/test_attachments.py::test_mime_spoof_is_415 PASSED [ 14%]
student-tests/test_attachments.py::test_empty_upload_is_415 PASSED [ 16%]
student-tests/test_attachments.py::test_unsafe_filename_is_400 PASSED [ 18%]
student-tests/test_attachments.py::test_empty_text_without_attachment_is_400 PASSED [ 20%]
student-tests/test_auth.py::test_registration_requires_password PASSED [ 22%]
student-tests/test_auth.py::test_short_password_is_400 PASSED [ 24%]
student-tests/test_auth.py::test_extra_field_is_400 PASSED [ 26%]
student-tests/test_auth.py::test_malformed_json_is_400 PASSED [ 28%]
student-tests/test_auth.py::test_duplicate_username_is_409 PASSED [ 30%]
student-tests/test_auth.py::test_registration_never_returns_password PASSED [ 32%]
student-tests/test_auth.py::test_wrong_password_is_401_basic PASSED [ 34%]
student-tests/test_auth.py::test_unknown_user_is_401_basic PASSED [ 36%]
student-tests/test_auth.py::test_basic_on_business_endpoint_is_401_bearer PASSED [ 38%]
student-tests/test_auth.py::test_missing_auth_is_401_bearer PASSED [ 40%]
student-tests/test_auth.py::test_unknown_bearer_is_401 PASSED [ 42%]
student-tests/test_auth.py::test_x_user_id_is_ignored PASSED [ 44%]
student-tests/test_auth.py::test_logout_revokes_session PASSED [ 46%]
student-tests/test_concurrency.py::test_100_concurrent_messages_are_not_lost PASSED [ 48%]
student-tests/test_idempotency.py::test_replay_same_key_returns_same_message PASSED [ 51%]
student-tests/test_idempotency.py::test_same_key_different_body_is_409 PASSED [ 53%]
student-tests/test_idempotency.py::test_missing_key_is_400 PASSED [ 55%]
student-tests/test_idempotency.py::test_invalid_key_is_400 PASSED [ 57%]
student-tests/test_idempotency.py::test_concurrent_same_key_creates_exactly_one_message PASSED [ 59%]
student-tests/test_instances.py::test_instance_header_present_on_success PASSED [ 61%]
student-tests/test_instances.py::test_instance_header_present_on_error PASSED [ 63%]
student-tests/test_instances.py::test_at_least_two_instances_seen_through_lb PASSED [ 65%]
student-tests/test_negative.py::test_foreign_chat_is_404 PASSED [ 67%]
student-tests/test_negative.py::test_empty_message_is_400 PASSED [ 69%]
student-tests/test_negative.py::test_oversized_message_is_400 PASSED [ 71%]
student-tests/test_negative.py::test_limit_out_of_range_is_400 PASSED [ 73%]
student-tests/test_negative.py::test_sender_id_in_body_is_rejected PASSED [ 75%]
student-tests/test_negative.py::test_chat_without_caller_is_400 PASSED [ 77%]
student-tests/test_negative.py::test_chat_with_unknown_member_is_400 PASSED [ 79%]
student-tests/test_negative.py::test_chat_with_duplicate_members_is_400 PASSED [ 81%]
student-tests/test_pagination.py::test_full_traversal_without_duplicates PASSED [ 83%]
student-tests/test_pagination.py::test_cursor_from_other_chat_is_400 PASSED [ 85%]
student-tests/test_pagination.py::test_garbage_cursor_is_400 PASSED [ 87%]
student-tests/test_pagination.py::test_well_formed_cursor_with_wrong_types_is_400 PASSED [ 89%]
student-tests/test_pipeline.py::test_variants_match_contract PASSED [ 91%]
student-tests/test_pipeline.py::test_missing_variant_is_404 PASSED [ 93%]
student-tests/test_race.py::test_concurrent_duplicate_username_single_winner PASSED [ 95%]
student-tests/test_race.py::test_failed_chat_creation_rolls_back PASSED [ 97%]
student-tests/test_session_revocation.py::test_logout_invalidates_across_replicas PASSED [100%]
============================= 49 passed in 15.19s =============================