исправление

This commit is contained in:
2026-10-26 19:40:34 +03:00
parent a591243d80
commit aaab3ac8b2
37 changed files with 1749 additions and 389 deletions
+24 -24
View File
@@ -1,29 +1,29 @@
python student-tests/attachment_failover.py
uploaded 111817 bytes -> 202 queued, sha256 99ea7533c441f79c..., served by api replica b0db3e40abfe
uploaded 111817 bytes -> 202 queued, sha256 99ea7533c441f79c..., served by api replica 48dc392933dc
SERVICE CONTAINER STATE STARTED AT (UTC)
api b0db3e40abfe running (healthy) 2026-10-25T18:23:36.991
api ef44b0d4c0a1 running (healthy) 2026-10-25T18:23:36.756
broker 9f909ed7ecea running (healthy) 2026-10-25T18:23:53.670
lb 8be67a2e86b7 running (healthy) 2026-10-25T18:20:04.043
migrate e6c2c825d38d exited 2026-10-25T18:28:07.167
postgres d2bfd48385f1 running (healthy) 2026-10-25T18:19:54.204
s3 892c7ca290f2 running (healthy) 2026-10-25T18:19:54.206
s3-init 08c2e7925d67 exited 2026-10-25T18:28:07.169
valkey 4e223cb9301e running (healthy) 2026-10-25T18:19:54.202
worker d9eced386d93 running (healthy) 2026-10-25T18:28:09.870
stopped b0db3e40abfe (docker stop) right after 202; HAProxy: api1 DOWN, api2 UP
api 48dc392933dc running (healthy) 2026-10-26T16:18:45.196
api c1b7e1ab5673 running (healthy) 2026-10-26T16:18:45.657
broker 9f909ed7ecea running (healthy) 2026-10-26T16:19:00.163
lb 8be67a2e86b7 running (healthy) 2026-10-26T16:15:42.154
migrate a5a9934b4d6b exited 2026-10-26T16:23:38.842
postgres d2bfd48385f1 running (healthy) 2026-10-26T16:15:17.840
s3 892c7ca290f2 running (healthy) 2026-10-26T16:15:17.826
s3-init deab1aa2b022 exited 2026-10-26T16:23:38.843
valkey 4e223cb9301e running (healthy) 2026-10-26T16:15:17.820
worker 292a36c54a41 running (healthy) 2026-10-26T16:23:41.416
stopped 48dc392933dc (docker stop) right after 202; HAProxy: api1 UP, api2 DOWN
the worker finished the job without that replica: status ready, variants ['thumbnail', 'crop', 'optimized']
downloaded 4 times through ['ef44b0d4c0a1']: same SHA-256 as uploaded
restored b0db3e40abfe; HAProxy: api1 UP, api2 UP
downloaded 4 times through ['c1b7e1ab5673']: same SHA-256 as uploaded
restored 48dc392933dc; HAProxy: api1 UP, api2 UP
SERVICE CONTAINER STATE STARTED AT (UTC)
api b0db3e40abfe running (healthy) 2026-10-25T18:28:33.999
api ef44b0d4c0a1 running (healthy) 2026-10-25T18:23:36.756
broker 9f909ed7ecea running (healthy) 2026-10-25T18:23:53.670
lb 8be67a2e86b7 running (healthy) 2026-10-25T18:20:04.043
migrate e6c2c825d38d exited 2026-10-25T18:28:07.167
postgres d2bfd48385f1 running (healthy) 2026-10-25T18:19:54.204
s3 892c7ca290f2 running (healthy) 2026-10-25T18:19:54.206
s3-init 08c2e7925d67 exited 2026-10-25T18:28:07.169
valkey 4e223cb9301e running (healthy) 2026-10-25T18:19:54.202
worker d9eced386d93 running (healthy) 2026-10-25T18:28:09.870
api 48dc392933dc running (healthy) 2026-10-26T16:24:32.726
api c1b7e1ab5673 running (healthy) 2026-10-26T16:18:45.657
broker 9f909ed7ecea running (healthy) 2026-10-26T16:19:00.163
lb 8be67a2e86b7 running (healthy) 2026-10-26T16:15:42.154
migrate a5a9934b4d6b exited 2026-10-26T16:23:38.842
postgres d2bfd48385f1 running (healthy) 2026-10-26T16:15:17.840
s3 892c7ca290f2 running (healthy) 2026-10-26T16:15:17.826
s3-init deab1aa2b022 exited 2026-10-26T16:23:38.843
valkey 4e223cb9301e running (healthy) 2026-10-26T16:15:17.820
worker 292a36c54a41 running (healthy) 2026-10-26T16:23:41.416
PASS: the replica that accepted the upload was stopped right after 202; the job still became ready and another replica returned the same bytes (the original lives in S3, not on the replica)
+14
View File
@@ -0,0 +1,14 @@
python student-tests/cleanup_race.py
A. failed b2299717-daa4-4704-afd1-19efe898e821 (retention expired); the janitor read the references and stopped
operator replay while the janitor waits -> {'result': 'queued', 'attempt': 2, 'previous_error': 'retry_exhausted'}
janitor continued: deleted 0, re-checked under the lock -> kept {'current_work': 1}; staging/b2299717... is still in S3
B. failed 6c7228dc-9d9f-4b3c-9f3d-aa6692124418 (retention expired); the janitor holds the lock: staging marked deleted, no COMMIT yet
replay waited 8.0 s for the lock -> refused (source_missing); job stays failed; journal: staging_expired -> replay_refused
A: worker started -> ready with ['thumbnail', 'crop', 'optimized'] (before the fix: failed / source_missing)
C. upload e0578869-000a-4a70-b43b-ab12f6d5ff49: staging written, no row in the database yet (API paused before COMMIT)
janitor (grace 0): skipped_busy 1, deleted 0 — the upload holds the attachment lock
upload -> 202, then ready with 3 variants
D. d4abfa4b-af5e-4208-8d4e-f69a1783891b: worker wrote the original and 3 variants, COMMIT not yet (status processing)
janitor (grace 0): the snapshot marked the original and 3 variants as unreferenced; re-checked under the lock -> kept {'current_work': 4}, deleted 0
worker committed -> ready; the original and all variants download with the same SHA-256
PASS: the janitor re-checks the state under the attachment lock before deleting: a replay accepted after its snapshot keeps the staging (A), a replay after the janitor's decision is refused safely (B), an upload in progress (C) and objects of a job in processing (D) are not deleted
+10 -10
View File
@@ -1,13 +1,13 @@
python student-tests/concurrency.py
time s | processing (DB) | unacked (broker) | waiting in queue
2.5 | 2 | 0 | 0
7.1 | 2 | 2 | 4
10.4 | 2 | 2 | 2
13.4 | 2 | 2 | 2
16.1 | 2 | 2 | 2
20.5 | 2 | 2 | 0
23.3 | 2 | 2 | 0
26.5 | 2 | 2 | 0
29.4 | 0 | 0 | 0
peak: 2 jobs in processing, 2 unacknowledged messages, up to 4 waiting in the queue; all 6 ready after 29.4 s
2.4 | 2 | 0 | 0
5.0 | 2 | 2 | 4
7.6 | 2 | 2 | 4
11.6 | 2 | 2 | 4
14.3 | 2 | 2 | 2
17.1 | 2 | 2 | 2
19.7 | 2 | 2 | 0
23.8 | 2 | 2 | 0
26.5 | 0 | 2 | 0
peak: 2 jobs in processing, 2 unacknowledged messages, up to 4 waiting in the queue; all 6 ready after 26.5 s
PASS: at most WORKER_CONCURRENCY=2 jobs run at once and the broker gives the worker at most prefetch=2 messages; the rest wait in the durable queue
+30 -12
View File
@@ -2,8 +2,26 @@ docker compose --profile tools run --rm db-test
Container mtusi-lab5-postgres-1 Running
Container mtusi-lab5-postgres-1 Waiting
Container mtusi-lab5-postgres-1 Healthy
Container mtusi-lab5-db-test-run-436c3e33e3cf Creating
Container mtusi-lab5-db-test-run-436c3e33e3cf Created
Container mtusi-lab5-db-test-run-dcea39c16e25 Creating
Container mtusi-lab5-db-test-run-dcea39c16e25 Created
test_1_replay_after_snapshot_keeps_staging (test_cleanup.CleanupRaceTest.test_1_replay_after_snapshot_keeps_staging) ...
snapshot -> replay (queued) -> cleanup: kept [('staging/224e34a0-91da-415f-acc4-ecc686b36842', 'current_work')], nothing deleted
ok
test_2_cleanup_first_then_replay_waits_and_refuses (test_cleanup.CleanupRaceTest.test_2_cleanup_first_then_replay_waits_and_refuses) ...
cleanup marked the staging deleted, holds the lock -> replay waited 1 s+ -> refused (source_missing); job stays failed; journal: staging_expired, replay_refused
ok
test_3_replay_first_then_cleanup_waits_and_keeps (test_cleanup.CleanupRaceTest.test_3_replay_first_then_cleanup_waits_and_keeps) ... ok
test_4_upload_in_progress_is_skipped (test_cleanup.CleanupRaceTest.test_4_upload_in_progress_is_skipped)
replay holds the lock -> cleanup waited -> kept [('staging/34b4b519-0cbc-4edb-baab-e86b337fdf38', 'current_work')]
...
upload between PUT and COMMIT -> cleanup skipped it (busy); after COMMIT -> current work, kept
ok
test_5_objects_of_processing_job_are_kept (test_cleanup.CleanupRaceTest.test_5_objects_of_processing_job_are_kept) ... ok
test_6_regular_cleanup_still_works (test_cleanup.CleanupRaceTest.test_6_regular_cleanup_still_works) ...
processing job (worker writes the original and variants before COMMIT) -> all 3 objects kept
orphan, staging after ready, objects of a failed attachment after retention -> deleted; published original and variants, a failed attachment within retention -> kept; dry-run deletes nothing
ok
test_backoff_bounds (test_jobs.JobsIntegrationTest.test_backoff_bounds) ... ok
test_claim_once_and_concurrent_claims (test_jobs.JobsIntegrationTest.test_claim_once_and_concurrent_claims) ...
10 concurrent claims of one job: 1 claimed, 9 in_progress
@@ -15,29 +33,29 @@ test_permanent_error_fails_at_once (test_jobs.JobsIntegrationTest.test_permanent
test_replay_rules (test_jobs.JobsIntegrationTest.test_replay_rules) ... ok
test_retry_backoff_then_exhausted (test_jobs.JobsIntegrationTest.test_retry_backoff_then_exhausted) ... ok
test_upload_creates_job_and_outbox_in_one_transaction (test_jobs.JobsIntegrationTest.test_upload_creates_job_and_outbox_in_one_transaction) ... ok
test_concurrent_registration_has_one_winner (test_store.StoreIntegrationTest.test_concurrent_registration_has_one_winner) ... ok
test_concurrent_same_idempotency_key_creates_one_row (test_store.StoreIntegrationTest.test_concurrent_same_idempotency_key_creates_one_row) ...
test_concurrent_registration_has_one_winner (test_store.StoreIntegrationTest.test_concurrent_registration_has_one_winner) ...
20 параллельных create_user: 1 создан, 19 получили Conflict (409)
ok
test_create_chat_rolls_back_when_failing_midway (test_store.StoreIntegrationTest.test_create_chat_rolls_back_when_failing_midway) ...
test_concurrent_same_idempotency_key_creates_one_row (test_store.StoreIntegrationTest.test_concurrent_same_idempotency_key_creates_one_row) ...
20 одновременных add_message с одним ключом: 1 строка, 1 новое + 19 повторов с тем же сообщением
ok
test_create_chat_rolls_back_when_failing_midway (test_store.StoreIntegrationTest.test_create_chat_rolls_back_when_failing_midway) ... ok
test_database_rejects_message_from_non_member (test_store.StoreIntegrationTest.test_database_rejects_message_from_non_member) ...
чат с несуществующим участником: транзакция откатилась, строк chats/chat_members не осталось
ok
test_database_rejects_message_from_non_member (test_store.StoreIntegrationTest.test_database_rejects_message_from_non_member) ...
INSERT сообщения от не-участника напрямую в БД: ForeignKeyViolation
ok
test_migrations_rerun_is_noop (test_store.StoreIntegrationTest.test_migrations_rerun_is_noop) ...
test_migrations_rerun_is_noop (test_store.StoreIntegrationTest.test_migrations_rerun_is_noop) ... ok
test_old_version_insert_without_key_still_works (test_store.StoreIntegrationTest.test_old_version_insert_without_key_still_works) ...
schema_migrations: ['001_core', '002_sessions', '003_text_as_bytes', '004_message_idempotency', '005_attachments', '006_jobs']; повторный migrate() ничего не применил
ok
test_old_version_insert_without_key_still_works (test_store.StoreIntegrationTest.test_old_version_insert_without_key_still_works) ...
INSERT как в lab2 (без ключа) после миграции 004 работает: старая версия совместима со схемой
ok
test_same_key_other_body_is_conflict (test_store.StoreIntegrationTest.test_same_key_other_body_is_conflict) ...
тот же ключ с другим телом: Conflict (409), в базе по-прежнему одна строка
ok
----------------------------------------------------------------------
Ran 16 tests in 0.624s
Ran 22 tests in 2.833s
OK
+47 -47
View File
@@ -1,64 +1,64 @@
python student-tests/run_failover.py
hook: scripts/stop-one.cmd; api replicas: ['b0db3e40abfe', 'ef44b0d4c0a1']
hook: scripts/stop-one.cmd; api replicas: ['48dc392933dc', 'c1b7e1ab5673']
=== run 1: containers before (HAProxy: api1 UP, api2 UP)
SERVICE CONTAINER STATE STARTED AT (UTC)
api b0db3e40abfe running (healthy) 2026-10-25T18:28:33.999
api ef44b0d4c0a1 running (healthy) 2026-10-25T18:23:36.756
broker 9f909ed7ecea running (healthy) 2026-10-25T18:23:53.670
lb 8be67a2e86b7 running (healthy) 2026-10-25T18:20:04.043
migrate e6c2c825d38d exited 2026-10-25T18:28:07.167
postgres d2bfd48385f1 running (healthy) 2026-10-25T18:19:54.204
s3 892c7ca290f2 running (healthy) 2026-10-25T18:29:00.995
s3-init 08c2e7925d67 exited 2026-10-25T18:28:07.169
valkey 4e223cb9301e running (healthy) 2026-10-25T18:19:54.202
worker d9eced386d93 running (healthy) 2026-10-25T18:28:09.870
api 48dc392933dc running (healthy) 2026-10-26T16:24:32.726
api c1b7e1ab5673 running (healthy) 2026-10-26T16:18:45.657
broker 9f909ed7ecea running (healthy) 2026-10-26T16:19:00.163
lb 8be67a2e86b7 running (healthy) 2026-10-26T16:15:42.154
migrate a5a9934b4d6b exited 2026-10-26T16:23:38.842
postgres d2bfd48385f1 running (healthy) 2026-10-26T16:15:17.840
s3 892c7ca290f2 running (healthy) 2026-10-26T16:24:57.683
s3-init deab1aa2b022 exited 2026-10-26T16:23:38.843
valkey 4e223cb9301e running (healthy) 2026-10-26T16:15:17.820
worker 292a36c54a41 running (healthy) 2026-10-26T16:23:41.416
Executing explicit failover hook; hook output suppressed to avoid leaking secrets.␍
{"observed_instances_before": 2, "successful_writes": 119, "failed_attempts": 0, "first_recovery_seconds": 5.11}␍
{"observed_instances_before": 2, "successful_writes": 124, "failed_attempts": 0, "first_recovery_seconds": 4.531}␍
PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
containers after (HAProxy: api1 UP)
SERVICE CONTAINER STATE STARTED AT (UTC)
api b0db3e40abfe running (healthy) 2026-10-25T18:28:33.999
api ef44b0d4c0a1 exited 2026-10-25T18:23:36.756
broker 9f909ed7ecea running (healthy) 2026-10-25T18:23:53.670
lb 8be67a2e86b7 running (healthy) 2026-10-25T18:20:04.043
migrate e6c2c825d38d exited 2026-10-25T18:28:07.167
postgres d2bfd48385f1 running (healthy) 2026-10-25T18:19:54.204
s3 892c7ca290f2 running (healthy) 2026-10-25T18:29:00.995
s3-init 08c2e7925d67 exited 2026-10-25T18:28:07.169
valkey 4e223cb9301e running (healthy) 2026-10-25T18:19:54.202
worker d9eced386d93 running (healthy) 2026-10-25T18:28:09.870
the hook stopped ef44b0d4c0a1 (X-Instance-Id of that replica = container ID); other api containers, postgres, valkey, s3 and lb kept running
restored: docker start ef44b0d4c0a1 -> healthy and back in HAProxy (api1 UP, api2 UP)
api 48dc392933dc exited 2026-10-26T16:24:32.726
api c1b7e1ab5673 running (healthy) 2026-10-26T16:18:45.657
broker 9f909ed7ecea running (healthy) 2026-10-26T16:19:00.163
lb 8be67a2e86b7 running (healthy) 2026-10-26T16:15:42.154
migrate a5a9934b4d6b exited 2026-10-26T16:23:38.842
postgres d2bfd48385f1 running (healthy) 2026-10-26T16:15:17.840
s3 892c7ca290f2 running (healthy) 2026-10-26T16:24:57.683
s3-init deab1aa2b022 exited 2026-10-26T16:23:38.843
valkey 4e223cb9301e running (healthy) 2026-10-26T16:15:17.820
worker 292a36c54a41 running (healthy) 2026-10-26T16:23:41.416
the hook stopped 48dc392933dc (X-Instance-Id of that replica = container ID); other api containers, postgres, valkey, s3 and lb kept running
restored: docker start 48dc392933dc -> healthy and back in HAProxy (api1 UP, api2 UP)
=== run 2: containers before (HAProxy: api1 UP, api2 UP)
SERVICE CONTAINER STATE STARTED AT (UTC)
api b0db3e40abfe running (healthy) 2026-10-25T18:28:33.999
api ef44b0d4c0a1 running (healthy) 2026-10-25T18:30:14.430
broker 9f909ed7ecea running (healthy) 2026-10-25T18:23:53.670
lb 8be67a2e86b7 running (healthy) 2026-10-25T18:20:04.043
migrate e6c2c825d38d exited 2026-10-25T18:28:07.167
postgres d2bfd48385f1 running (healthy) 2026-10-25T18:19:54.204
s3 892c7ca290f2 running (healthy) 2026-10-25T18:29:00.995
s3-init 08c2e7925d67 exited 2026-10-25T18:28:07.169
valkey 4e223cb9301e running (healthy) 2026-10-25T18:19:54.202
worker d9eced386d93 running (healthy) 2026-10-25T18:28:09.870
api 48dc392933dc running (healthy) 2026-10-26T16:25:57.020
api c1b7e1ab5673 running (healthy) 2026-10-26T16:18:45.657
broker 9f909ed7ecea running (healthy) 2026-10-26T16:19:00.163
lb 8be67a2e86b7 running (healthy) 2026-10-26T16:15:42.154
migrate a5a9934b4d6b exited 2026-10-26T16:23:38.842
postgres d2bfd48385f1 running (healthy) 2026-10-26T16:15:17.840
s3 892c7ca290f2 running (healthy) 2026-10-26T16:24:57.683
s3-init deab1aa2b022 exited 2026-10-26T16:23:38.843
valkey 4e223cb9301e running (healthy) 2026-10-26T16:15:17.820
worker 292a36c54a41 running (healthy) 2026-10-26T16:23:41.416
Executing explicit failover hook; hook output suppressed to avoid leaking secrets.␍
{"observed_instances_before": 2, "successful_writes": 125, "failed_attempts": 0, "first_recovery_seconds": 5.531}␍
{"observed_instances_before": 2, "successful_writes": 124, "failed_attempts": 0, "first_recovery_seconds": 4.594}␍
PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
containers after (HAProxy: api2 UP)
SERVICE CONTAINER STATE STARTED AT (UTC)
api b0db3e40abfe exited 2026-10-25T18:28:33.999
api ef44b0d4c0a1 running (healthy) 2026-10-25T18:30:14.430
broker 9f909ed7ecea running (healthy) 2026-10-25T18:23:53.670
lb 8be67a2e86b7 running (healthy) 2026-10-25T18:20:04.043
migrate e6c2c825d38d exited 2026-10-25T18:28:07.167
postgres d2bfd48385f1 running (healthy) 2026-10-25T18:19:54.204
s3 892c7ca290f2 running (healthy) 2026-10-25T18:29:00.995
s3-init 08c2e7925d67 exited 2026-10-25T18:28:07.169
valkey 4e223cb9301e running (healthy) 2026-10-25T18:19:54.202
worker d9eced386d93 running (healthy) 2026-10-25T18:28:09.870
the hook stopped b0db3e40abfe (X-Instance-Id of that replica = container ID); other api containers, postgres, valkey, s3 and lb kept running
restored: docker start b0db3e40abfe -> healthy and back in HAProxy (api1 UP, api2 UP)
api 48dc392933dc running (healthy) 2026-10-26T16:25:57.020
api c1b7e1ab5673 exited 2026-10-26T16:18:45.657
broker 9f909ed7ecea running (healthy) 2026-10-26T16:19:00.163
lb 8be67a2e86b7 running (healthy) 2026-10-26T16:15:42.154
migrate a5a9934b4d6b exited 2026-10-26T16:23:38.842
postgres d2bfd48385f1 running (healthy) 2026-10-26T16:15:17.840
s3 892c7ca290f2 running (healthy) 2026-10-26T16:24:57.683
s3-init deab1aa2b022 exited 2026-10-26T16:23:38.843
valkey 4e223cb9301e running (healthy) 2026-10-26T16:15:17.820
worker 292a36c54a41 running (healthy) 2026-10-26T16:23:41.416
the hook stopped c1b7e1ab5673 (X-Instance-Id of that replica = container ID); other api containers, postgres, valkey, s3 and lb kept running
restored: docker start c1b7e1ab5673 -> healthy and back in HAProxy (api1 UP, api2 UP)
PASS: public failover test passed 2 times; every api replica was stopped once and restored
+29 -29
View File
@@ -1,36 +1,36 @@
python student-tests/failure_s3.py
=== s3 stopped
SERVICE CONTAINER STATE STARTED AT (UTC)
api b0db3e40abfe running (healthy) 2026-10-25T18:28:33.999
api ef44b0d4c0a1 running (healthy) 2026-10-25T18:23:36.756
broker 9f909ed7ecea running (healthy) 2026-10-25T18:23:53.670
lb 8be67a2e86b7 running (healthy) 2026-10-25T18:20:04.043
migrate e6c2c825d38d exited 2026-10-25T18:28:07.167
postgres d2bfd48385f1 running (healthy) 2026-10-25T18:19:54.204
s3 892c7ca290f2 exited 2026-10-25T18:19:54.206
s3-init 08c2e7925d67 exited 2026-10-25T18:28:07.169
valkey 4e223cb9301e running (healthy) 2026-10-25T18:19:54.202
worker d9eced386d93 running (healthy) 2026-10-25T18:28:09.870
both api replicas are out of the balancer after 1.0 s: api1 DOWN, api2 DOWN
replica b0db3e40abfe: /health/live 200, /health/ready 503
replica ef44b0d4c0a1: /health/live 200, /health/ready 503
GET /health/ready -> 503 unavailable in 0.00 s (answered by the balancer)
POST /api/v1/chats/6f457b5b-fe8c-45c4-a569-dcb9e04b2539/attachments -> 503 unavailable in 0.00 s (answered by the balancer)
GET /api/v1/attachments/9605875a-7999-471f-8e6b-500c0d99ccb6/content -> 503 unavailable in 0.00 s (answered by the balancer)
GET /api/v1/chats/6f457b5b-fe8c-45c4-a569-dcb9e04b2539/messages -> 503 unavailable in 0.00 s (answered by the balancer)
api 48dc392933dc running (healthy) 2026-10-26T16:24:32.726
api c1b7e1ab5673 running (healthy) 2026-10-26T16:18:45.657
broker 9f909ed7ecea running (healthy) 2026-10-26T16:19:00.163
lb 8be67a2e86b7 running (healthy) 2026-10-26T16:15:42.154
migrate a5a9934b4d6b exited 2026-10-26T16:23:38.842
postgres d2bfd48385f1 running (healthy) 2026-10-26T16:15:17.840
s3 892c7ca290f2 exited 2026-10-26T16:15:17.826
s3-init deab1aa2b022 exited 2026-10-26T16:23:38.843
valkey 4e223cb9301e running (healthy) 2026-10-26T16:15:17.820
worker 292a36c54a41 running (healthy) 2026-10-26T16:23:41.416
both api replicas are out of the balancer after 0.9 s: api1 DOWN, api2 DOWN
replica 48dc392933dc: /health/live 200, /health/ready 503
replica c1b7e1ab5673: /health/live 200, /health/ready 503
GET /health/ready -> 503 unavailable in 0.05 s (answered by the balancer)
POST /api/v1/chats/c3165ff5-5952-4666-84df-aa7e4dab7fb9/attachments -> 503 unavailable in 0.00 s (answered by the balancer)
GET /api/v1/attachments/bfbc3aa5-81f0-46d0-a26d-f901b8d9ee86/content -> 503 unavailable in 0.00 s (answered by the balancer)
GET /api/v1/chats/c3165ff5-5952-4666-84df-aa7e4dab7fb9/messages -> 503 unavailable in 0.02 s (answered by the balancer)
=== s3 started
replicas are back in the balancer after 23.7 s: api1 UP, api2 UP
replicas are back in the balancer after 18.0 s: api1 UP, api2 UP
the file uploaded before the outage is intact (sha256 99ea7533c441f79c...)
new upload -> 202 -> ready (cd112988-40ba-4267-951d-033ea82b1ca3)
new upload -> 202 -> ready (59e03ee4-d3ff-40e9-b1e6-6a1d6fee4720)
SERVICE CONTAINER STATE STARTED AT (UTC)
api b0db3e40abfe running (healthy) 2026-10-25T18:28:33.999
api ef44b0d4c0a1 running (healthy) 2026-10-25T18:23:36.756
broker 9f909ed7ecea running (healthy) 2026-10-25T18:23:53.670
lb 8be67a2e86b7 running (healthy) 2026-10-25T18:20:04.043
migrate e6c2c825d38d exited 2026-10-25T18:28:07.167
postgres d2bfd48385f1 running (healthy) 2026-10-25T18:19:54.204
s3 892c7ca290f2 running (healthy) 2026-10-25T18:29:00.995
s3-init 08c2e7925d67 exited 2026-10-25T18:28:07.169
valkey 4e223cb9301e running (healthy) 2026-10-25T18:19:54.202
worker d9eced386d93 running (healthy) 2026-10-25T18:28:09.870
api 48dc392933dc running (unhealthy) 2026-10-26T16:24:32.726
api c1b7e1ab5673 running (unhealthy) 2026-10-26T16:18:45.657
broker 9f909ed7ecea running (healthy) 2026-10-26T16:19:00.163
lb 8be67a2e86b7 running (unhealthy) 2026-10-26T16:15:42.154
migrate a5a9934b4d6b exited 2026-10-26T16:23:38.842
postgres d2bfd48385f1 running (healthy) 2026-10-26T16:15:17.840
s3 892c7ca290f2 running (starting) 2026-10-26T16:24:57.683
s3-init deab1aa2b022 exited 2026-10-26T16:23:38.843
valkey 4e223cb9301e running (healthy) 2026-10-26T16:15:17.820
worker 292a36c54a41 running (healthy) 2026-10-26T16:23:41.416
PASS: S3 down -> replicas not ready (live 200, ready 503), the balancer answers 503 in the contract format, no 500 and no hanging; after S3 is back the original is intact and uploads work again
+10 -4
View File
@@ -1,6 +1,6 @@
docker compose --profile tools run --rm imaging-test
Container mtusi-lab5-imaging-test-run-522cead2dfe0 Creating
Container mtusi-lab5-imaging-test-run-522cead2dfe0 Created
Container mtusi-lab5-imaging-test-run-7b65aee97073 Creating
Container mtusi-lab5-imaging-test-run-7b65aee97073 Created
test_alpha_is_white_in_jpeg_and_kept_in_webp (test_imaging.ImagingTest.test_alpha_is_white_in_jpeg_and_kept_in_webp) ... ok
test_broken_jpeg_scan_is_invalid (test_imaging.ImagingTest.test_broken_jpeg_scan_is_invalid) ... ok
test_exif_orientation_is_applied (test_imaging.ImagingTest.test_exif_orientation_is_applied) ...
@@ -10,14 +10,20 @@ test_fixture_variants (test_imaging.ImagingTest.test_fixture_variants) ...
fixture 320×200 -> thumbnail JPEG 256×160, crop JPEG 128×128, optimized WebP 320×200
ok
test_geometry (test_imaging.ImagingTest.test_geometry) ... ok
test_jpeg_header_check_matches_strict_decoder (test_imaging.ImagingTest.test_jpeg_header_check_matches_strict_decoder) ...
800 random header mutations: {'both accept': 318, 'both reject': 427, 'accepted, entropy error in worker': 55}
ok
test_limits_in_child_process (test_imaging.ImagingTest.test_limits_in_child_process) ...
36 Mpx RGBA in a child process: ok in 3.78 s with 640 MiB; MemoryError -> image_too_large with 200 MiB; timeout 0.2 s -> killed after 0.21 s; 1000 px limit -> image_too_large
36 Mpx RGBA in a child process: ok in 3.93 s with 640 MiB; MemoryError -> image_too_large with 200 MiB; timeout 0.2 s -> killed after 0.21 s; 1000 px limit -> image_too_large
ok
test_metadata_is_stripped (test_imaging.ImagingTest.test_metadata_is_stripped) ... ok
test_modes (test_imaging.ImagingTest.test_modes) ... ok
test_same_input_same_bytes (test_imaging.ImagingTest.test_same_input_same_bytes) ... ok
test_subsampling_rule_matches_turbojpeg (test_imaging.ImagingTest.test_subsampling_rule_matches_turbojpeg) ...
8208 sampling-factor combinations: API and TurboJPEG agree on every one
ok
----------------------------------------------------------------------
Ran 9 tests in 5.420s
Ran 11 tests in 6.036s
OK
+5 -5
View File
@@ -1,9 +1,9 @@
python student-tests/lease_takeover.py
1. long job (35 s > lease 30 s) on d9eced386d93/507dfab2: lease_until moved forward 2 times: 18:26:08 -> 18:26:10 -> 18:26:20
2. worker B 3b645a26424d started (the job is still held by A's lease)
worker A d9eced386d93 frozen (docker pause): no more renewals
lease expired -> attempt 2 -> ready 31 s after the freeze; result committed by worker-3b645a26424d/a5b5d050
1. long job (35 s > lease 30 s) on 292a36c54a41/4b7735c2: lease_until moved forward 2 times: 16:21:03 -> 16:21:13 -> 16:21:23
2. worker B fa1bafe61888 started (the job is still held by A's lease)
worker A 292a36c54a41 frozen (docker pause): no more renewals
lease expired -> attempt 2 -> ready 33 s after the freeze; result committed by worker-fa1bafe61888/279ac631
events: queued(1) -> claimed(1) -> lease_expired(1) -> retry_scheduled(1) -> claimed(2) -> ready(2)
3. worker A unpaused: Задание cd53da75-5133-44f3-a33f-038d4dbfd6ca: lease забрал другой worker — работа брошена
3. worker A unpaused: Задание d08bfc08-1460-4633-bbfd-6b3f69088ca3: lease забрал другой worker — работа брошена
still exactly one result: status ready, attempt 2, 3 variant rows, metadata unchanged
PASS: a running worker keeps its lease by renewing it; a frozen one loses it, the job moves to another worker, and the stale worker cannot overwrite the result (fencing token)
+12 -12
View File
@@ -1,19 +1,19 @@
python student-tests/outbox_crash.py
A. api_after_commit: the client got 502 instead of 202, but the attachment 44f59913-f920-4d36-82d5-fea3d61ce5b7 and its outbox row were committed before the crash
ready without creating a new job by hand; api restarted by Docker: ['ef44b0d4c0a1']
outbox: row 41 published 2026-10-25T18:23:23.278264+00:00 by relay-b0db3e40abfe
A. api_after_commit: the client got 502 instead of 202, but the attachment 68ccecb0-ae64-4a1d-a235-63219f66c403 and its outbox row were committed before the crash
ready without creating a new job by hand; api restarted by Docker: ['48dc392933dc']
outbox: row 130 published 2026-10-26T16:18:31.010950+00:00 by relay-c1b7e1ab5673
events: queued -> claimed -> ready
B. relay_before_publish: upload -> 202 (0d6338d9-fa65-459d-9d54-53cc385700d4); every relay that takes the row crashes before publishing
crashed and restarted: ['b0db3e40abfe', 'ef44b0d4c0a1']; after restart the row was published once -> ready
outbox: row 42 published 2026-10-25T18:23:32.331225+00:00 by relay-ef44b0d4c0a1
B. relay_before_publish: upload -> 202 (780f7bd8-df89-4c70-84fa-9d90f35879fa); every relay that takes the row crashes before publishing
crashed and restarted: ['48dc392933dc', 'c1b7e1ab5673']; after restart the row was published once -> ready
outbox: row 131 published 2026-10-26T16:18:40.873234+00:00 by relay-48dc392933dc
events: queued -> claimed -> ready
C. relay_after_publish: upload -> 202 (cf7c7e33-78ee-48c1-9bc5-7acefbf49d40); the broker confirms, the relay crashes before marking the row
crashed and restarted: ['b0db3e40abfe', 'ef44b0d4c0a1']; the same message was delivered again 1 time(s): duplicate_ignored
outbox: row 43 published 2026-10-25T18:23:40.297286+00:00 by relay-ef44b0d4c0a1
C. relay_after_publish: upload -> 202 (87559a9a-a61c-4a10-999c-516b5e1f481a); the broker confirms, the relay crashes before marking the row
crashed and restarted: ['48dc392933dc', 'c1b7e1ab5673']; the same message was delivered again 1 time(s): duplicate_ignored
outbox: row 132 published 2026-10-26T16:18:48.678466+00:00 by relay-48dc392933dc
events: queued -> claimed -> ready -> duplicate_ignored
still one set of variants: 3 rows, 3 objects
D. broker stopped: upload -> 202 (094e50ca-898e-4c19-9d39-1b80721409ab), after 5 s status queued, outbox row 44 not published yet (it waits in PostgreSQL)
broker started: the relay published the row, ready 6.4 s later
outbox: row 44 published 2026-10-25T18:24:08.645165+00:00 by relay-ef44b0d4c0a1
D. broker stopped: upload -> 202 (87e3efc2-e44b-4260-8129-7fadffec4811), after 5 s status queued, outbox row 133 not published yet (it waits in PostgreSQL)
broker started: the relay published the row, ready 11.8 s later
outbox: row 133 published 2026-10-26T16:19:07.785521+00:00 by relay-48dc392933dc
events: queued -> claimed -> ready
PASS: a crash between COMMIT and publish (A, B) loses nothing — the outbox row is published later and the job becomes ready without manual action; a crash after publish (C) only causes a duplicate delivery, which the worker acknowledges without a second set of variants; while the broker is down (D) uploads are still accepted and the jobs wait in the outbox
+29 -29
View File
@@ -2,36 +2,36 @@ python student-tests/run_persistence.py
hook: scripts/restart.cmd
=== containers before
SERVICE CONTAINER STATE STARTED AT (UTC)
api b0db3e40abfe running (healthy) 2026-10-25T18:30:40.428
api ef44b0d4c0a1 running (healthy) 2026-10-25T18:30:14.430
broker 9f909ed7ecea running (healthy) 2026-10-25T18:23:53.670
lb 8be67a2e86b7 running (healthy) 2026-10-25T18:20:04.043
migrate e6c2c825d38d exited 2026-10-25T18:28:07.167
postgres d2bfd48385f1 running (healthy) 2026-10-25T18:19:54.204
s3 892c7ca290f2 running (healthy) 2026-10-25T18:29:00.995
s3-init 08c2e7925d67 exited 2026-10-25T18:28:07.169
valkey 4e223cb9301e running (healthy) 2026-10-25T18:19:54.202
worker d9eced386d93 running (healthy) 2026-10-25T18:28:09.870
api 48dc392933dc running (healthy) 2026-10-26T16:25:57.020
api c1b7e1ab5673 running (healthy) 2026-10-26T16:26:21.371
broker 9f909ed7ecea running (healthy) 2026-10-26T16:19:00.163
lb 8be67a2e86b7 running (healthy) 2026-10-26T16:15:42.154
migrate a5a9934b4d6b exited 2026-10-26T16:23:38.842
postgres d2bfd48385f1 running (healthy) 2026-10-26T16:15:17.840
s3 892c7ca290f2 running (healthy) 2026-10-26T16:24:57.683
s3-init deab1aa2b022 exited 2026-10-26T16:23:38.843
valkey 4e223cb9301e running (healthy) 2026-10-26T16:15:17.820
worker 292a36c54a41 running (healthy) 2026-10-26T16:23:41.416
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 (test took 44.6 s: hook + waiting for readiness + data checks)
=== containers after (test took 49.6 s: hook + waiting for readiness + data checks)
SERVICE CONTAINER STATE STARTED AT (UTC)
api b0db3e40abfe running (healthy) 2026-10-25T18:31:28.449
api ef44b0d4c0a1 running (healthy) 2026-10-25T18:31:28.805
broker 9f909ed7ecea running (healthy) 2026-10-25T18:30:56.986
lb 8be67a2e86b7 running (healthy) 2026-10-25T18:31:31.925
migrate e6c2c825d38d exited 2026-10-25T18:31:11.567
postgres d2bfd48385f1 running (healthy) 2026-10-25T18:30:55.983
s3 892c7ca290f2 running (healthy) 2026-10-25T18:31:10.564
s3-init 08c2e7925d67 exited 2026-10-25T18:31:26.062
valkey 4e223cb9301e running (healthy) 2026-10-25T18:30:56.073
worker d9eced386d93 running (healthy) 2026-10-25T18:31:28.448
api ef44b0d4c0a1: same container, start time 18:30:14 -> 18:31:28
api b0db3e40abfe: same container, start time 18:30:40 -> 18:31:28
broker 9f909ed7ecea: same container, start time 18:23:53 -> 18:30:56
lb 8be67a2e86b7: same container, start time 18:20:04 -> 18:31:31
postgres d2bfd48385f1: same container, start time 18:19:54 -> 18:30:55
s3 892c7ca290f2: same container, start time 18:29:00 -> 18:31:10
valkey 4e223cb9301e: same container, start time 18:19:54 -> 18:30:56
worker d9eced386d93: same container, start time 18:28:09 -> 18:31:28
api 48dc392933dc running (healthy) 2026-10-26T16:27:12.404
api c1b7e1ab5673 running (healthy) 2026-10-26T16:27:12.751
broker 9f909ed7ecea running (healthy) 2026-10-26T16:26:35.888
lb 8be67a2e86b7 running (healthy) 2026-10-26T16:27:16.490
migrate a5a9934b4d6b exited 2026-10-26T16:26:50.586
postgres d2bfd48385f1 running (healthy) 2026-10-26T16:26:34.837
s3 892c7ca290f2 running (healthy) 2026-10-26T16:26:49.628
s3-init deab1aa2b022 exited 2026-10-26T16:27:10.098
valkey 4e223cb9301e running (healthy) 2026-10-26T16:26:34.974
worker 292a36c54a41 running (healthy) 2026-10-26T16:27:12.399
api 48dc392933dc: same container, start time 16:25:57 -> 16:27:12
api c1b7e1ab5673: same container, start time 16:26:21 -> 16:27:12
broker 9f909ed7ecea: same container, start time 16:19:00 -> 16:26:35
lb 8be67a2e86b7: same container, start time 16:15:42 -> 16:27:16
postgres d2bfd48385f1: same container, start time 16:15:17 -> 16:26:34
s3 892c7ca290f2: same container, start time 16:24:57 -> 16:26:49
valkey 4e223cb9301e: same container, start time 16:15:17 -> 16:26:34
worker 292a36c54a41: same container, start time 16:23:41 -> 16:27:12
PASS: api replicas, worker, postgres, valkey, s3, broker and lb were restarted (same containers and volumes, new start time); data, the attachment bytes and the existing token survived
+2 -2
View File
@@ -1,8 +1,8 @@
python student-tests/redelivery.py
1. attachment a8404f7e-b179-4332-a562-4508d5a31ee5 ready: 3 variant rows, objects ['variants/a8404f7e-b179-4332-a562-4508d5a31ee5/v1/crop.jpg', 'variants/a8404f7e-b179-4332-a562-4508d5a31ee5/v1/optimized.webp', 'variants/a8404f7e-b179-4332-a562-4508d5a31ee5/v1/thumbnail.jpg']
1. attachment 0e1796c4-b771-4b97-a8d6-27f3d24d5dd4 ready: 3 variant rows, objects ['variants/0e1796c4-b771-4b97-a8d6-27f3d24d5dd4/v1/crop.jpg', 'variants/0e1796c4-b771-4b97-a8d6-27f3d24d5dd4/v1/optimized.webp', 'variants/0e1796c4-b771-4b97-a8d6-27f3d24d5dd4/v1/thumbnail.jpg']
2. the same message (same job_id and attempt) published twice more
3. both duplicates acknowledged without processing: duplicate_ignored(задание уже ready: повторная доставка, ack без обработки), duplicate_ignored(задание уже ready: повторная доставка, ack без обработки)
variants: [('crop', '97bf1400b30a'), ('optimized', '1090d84ed841'), ('thumbnail', '7bc40bf315c8')] — same rows, same objects, status ready, attempt 1
4. 3 messages that do not match jobs.schema.json -> reject -> DLQ attachments.dead: 8 -> 11
4. 3 messages that do not match jobs.schema.json -> reject -> DLQ attachments.dead: 34 -> 37
the worker keeps working: a new upload became ready
PASS: redelivery of a finished job is a no-op with ack (no second set of variants); malformed messages go to the DLQ without crashing the worker
+3 -3
View File
@@ -1,10 +1,10 @@
python student-tests/retry_replay.py
A. transient errors twice, then success: ready at attempt 3
pauses before attempts: #2: 1.83 s, #3: 2.17 s (backoff 2^n with random jitter in [d/2, d])
pauses before attempts: #2: 1.98 s, #3: 2.19 s (backoff 2^n with random jitter in [d/2, d])
events: queued(1) -> claimed(1) -> retry_scheduled(1) -> claimed(2) -> retry_scheduled(2) -> claimed(3) -> ready(3)
B. transient error every time: 5 attempts -> failed, error_code=retry_exhausted (last error storage_unavailable)
pauses: #2: 1.84 s, #3: 2.45 s, #4: 6.81 s, #5: 15.37 s
DLQ attachments.dead: 11 -> 12; registry: python -m messenger.jobs failed lists it; content -> 409, attach -> 409
pauses: #2: 1.96 s, #3: 2.31 s, #4: 5.86 s, #5: 13.62 s
DLQ attachments.dead: 30 -> 31; registry: python -m messenger.jobs failed lists it; content -> 409, attach -> 409
C. permanent error: broken JPEG scan -> failed at attempt 1, error_code=invalid_image (no retries)
D. replay of the failed job: {'result': 'queued', 'attempt': 6, 'previous_error': 'retry_exhausted'} -> ready at attempt 6; audit: operator:student-test: replay оператора: было retry_exhausted (последняя ошибка storage_unavailable); новая попытка 6, ещё 5 попыток
replay of the now ready job: {'result': 'noop', 'reason': 'ready'} — no new message, variants unchanged (3 rows), status ready
+4 -4
View File
@@ -13,11 +13,11 @@ SeaweedFS admin/UI port 8888 inside the network: closed
SeaweedFS admin/UI port 8080 inside the network: closed
host 127.0.0.1:9000, :9333, :8888: closed (S3 is not published)
attachments columns: id:uuid, chat_id:uuid, owner_id:uuid, filename:text, content_type:text, size_bytes:bigint, sha256:text, width:integer, height:integer, storage_key:text, status:text, created_at:timestamp with time zone, updated_at:timestamp with time zone, error_code:text, staging_key:text
api b0db3e40abfe: files with the same SHA-256 on disk: 0
api ef44b0d4c0a1: files with the same SHA-256 on disk: 0
worker d9eced386d93: files with the same SHA-256 on disk: 0
api 48dc392933dc: files with the same SHA-256 on disk: 0
api c1b7e1ab5673: files with the same SHA-256 on disk: 0
worker 292a36c54a41: files with the same SHA-256 on disk: 0
broker message (243 bytes): ['attachment_id', 'attempt', 'created_at', 'job_id', 'pipeline_version', 'schema_version', 'type'] — only IDs and service fields
s3-init run 1: exit 0: s3-init: bucket messenger-attachments already exists; anonymous access: 403 (private)
s3-init run 2: exit 0: s3-init: bucket messenger-attachments already exists; anonymous access: 403 (private)
objects in bucket before/after bootstrap: 164/164; the file still downloads
objects in bucket before/after bootstrap: 360/360; the file still downloads
PASS: bucket is private outside the API, the API S3 user has least privilege, the console is closed, bytes are only in S3, bucket bootstrap is idempotent
+16 -16
View File
@@ -2,17 +2,17 @@ python student-tests/check_stack.py
docker: 29.6.2
compose: 5.3.1
container_name: not set for any service (replicas of one service are possible)
api replicas running: 2 -> ['b0db3e40abfe', 'ef44b0d4c0a1'] (deploy.replicas = 2)
api replicas running: 2 -> ['48dc392933dc', 'c1b7e1ab5673'] (deploy.replicas = 2)
service container cpus memory published ports networks
worker 292a36c54a41 1.00 1024Mi - backend
api 48dc392933dc 1.00 512Mi - backend, edge
valkey 4e223cb9301e 0.50 128Mi - backend
s3 892c7ca290f2 0.50 512Mi - backend
lb 8be67a2e86b7 0.50 128Mi 127.0.0.1:8080->8080/tcp, 127.0.0.1:8081->8081/tcp, 127.0.0.1:8404->8404/tcp edge
broker 9f909ed7ecea 1.00 512Mi - backend
api b0db3e40abfe 1.00 512Mi - backend, edge
api c1b7e1ab5673 1.00 512Mi - backend, edge
postgres d2bfd48385f1 1.00 512Mi - backend
worker d9eced386d93 1.00 1024Mi - backend
api ef44b0d4c0a1 1.00 512Mi - backend, edge
published: only lb, only on 127.0.0.1 (api replicas have no ports)
balancer: every api server is under the /health/ready check, no backup servers -> api1 UP (L7OK), api2 UP (L7OK)
@@ -25,15 +25,15 @@ images: lb haproxy:3.2.25-alpine; api mtusi-messenger:lab5; worker mtusi-messen
PASS: one entry point (lb on 127.0.0.1), >= 2 api replicas without ports and container_name, only ready replicas get traffic, CPU/RAM limits everywhere, stores (incl. S3) only on the internal network, S3 admin credentials only in s3-init; broker and worker are separate services
docker compose ps -a --format "table {{.Service}}\t{{.ID}}\t{{.Status}}"
SERVICE CONTAINER ID STATUS
api b0db3e40abfe Up 34 seconds (healthy)
api ef44b0d4c0a1 Up 34 seconds (healthy)
broker 9f909ed7ecea Up 43 seconds (healthy)
lb 8be67a2e86b7 Up 33 seconds (healthy)
migrate e6c2c825d38d Exited (0) 35 seconds ago
postgres d2bfd48385f1 Up 43 seconds (healthy)
s3 892c7ca290f2 Up 43 seconds (healthy)
s3-init 08c2e7925d67 Exited (0) 35 seconds ago
valkey 4e223cb9301e Up 43 seconds (healthy)
worker d9eced386d93 Up 34 seconds (healthy)
s3-init-1 | s3-init: bucket messenger-attachments created; anonymous access: 403 (private)
migrate-1 | 2026-10-25 18:20:01,879 INFO messenger.db: Миграции применены: 001_core, 002_sessions, 003_text_as_bytes, 004_message_idempotency, 005_attachments, 006_jobs
api 48dc392933dc Up 49 seconds (healthy)
api c1b7e1ab5673 Up 49 seconds (healthy)
broker 9f909ed7ecea Up About a minute (healthy)
lb 8be67a2e86b7 Up 48 seconds (healthy)
migrate a5a9934b4d6b Exited (0) About a minute ago
postgres d2bfd48385f1 Up About a minute (healthy)
s3 892c7ca290f2 Up About a minute (healthy)
s3-init deab1aa2b022 Exited (0) 50 seconds ago
valkey 4e223cb9301e Up About a minute (healthy)
worker 292a36c54a41 Up 49 seconds (healthy)
s3-init-1 | s3-init: bucket messenger-attachments already exists; anonymous access: 403 (private)
migrate-1 | 2026-10-26 16:15:25,625 INFO messenger.db: Миграции: новых нет, схема актуальна
+2 -2
View File
@@ -1,10 +1,10 @@
python student-tests/staging_cleanup.py
1. ready 232becfa-7e6d-44da-bb4d-e72e9d0cc9fd: staging removed by the worker right after COMMIT; original and variants kept
1. ready a285845a-2a6d-438d-a37c-f5ce252e5ce6: staging removed by the worker right after COMMIT; original and variants kept
2. prepared: staging leftover of a ready attachment, orphan staging, orphan variant, staging of a failed attachment, staging of a queued job (worker stopped)
3. dry-run: {"staging_after_ready": 2, "staging_failed_expired": 0, "orphan": 2} found, deleted 0
grace 900 s: deleted 0 — everything is younger than the grace period
grace 2 s: {"staging_after_ready": 2, "staging_failed_expired": 0, "orphan": 2}, deleted 4; kept: ready original and variants, staging of the queued job, staging of the failed attachment (retention)
retention 0 s: failed staging deleted ({"staging_after_ready": 0, "staging_failed_expired": 3, "orphan": 0}); replay now: {'result': 'refused', 'reason': 'source_missing', 'detail': 'оригинал в staging уже удалён (истёк STAGING_RETENTION_SECONDS)'}
repeated run: deleted 0
4. worker started: f8dce515-9269-42bf-a961-6ef73c87d763 ready, its staging removed
4. worker started: 002336e3-fb36-4738-b420-29d5362140cb ready, its staging removed
PASS: staging is removed after the result is committed; objects without a reference in the database are removed only after the grace period; the staging of failed uploads is kept for replay until retention ends; dry-run and repeated runs are safe
+9 -7
View File
@@ -23,8 +23,10 @@ test_mime_spoofing_is_415 (test_attachments.AttachmentTest.test_mime_spoofing_is
test_outsider_and_anonymous_cannot_upload (test_attachments.AttachmentTest.test_outsider_and_anonymous_cannot_upload) ... ok
test_pixel_bomb_is_413 (test_attachments.AttachmentTest.test_pixel_bomb_is_413) ... ok
test_png_and_jpeg_roundtrip_for_member (test_attachments.AttachmentTest.test_png_and_jpeg_roundtrip_for_member) ... ok
test_structurally_broken_jpeg_is_415 (test_attachments.AttachmentTest.test_structurally_broken_jpeg_is_415) ... ok
test_too_large_is_413_before_reading (test_attachments.AttachmentTest.test_too_large_is_413_before_reading) ... ok
test_too_large_stream_is_413 (test_attachments.AttachmentTest.test_too_large_stream_is_413) ... ok
test_valid_jpeg_variants_are_accepted (test_attachments.AttachmentTest.test_valid_jpeg_variants_are_accepted) ... ok
test_variants_and_bad_ids (test_attachments.AttachmentTest.test_variants_and_bad_ids) ... ok
test_variants_follow_the_contract (test_attachments.AttachmentTest.test_variants_follow_the_contract) ... ok
test_bearer_required_on_business_endpoints (test_auth.AuthTest.test_bearer_required_on_business_endpoints) ... ok
@@ -53,7 +55,7 @@ test_replay_through_another_replica_returns_same_message (test_idempotency.Idemp
test_same_key_other_body_is_409 (test_idempotency.IdempotencyTest.test_same_key_other_body_is_409) ... ok
----------------------------------------------------------------------
Ran 52 tests in 24.217s
Ran 54 tests in 25.793s
OK
@@ -63,13 +65,13 @@ OK
X-Instance-Id есть в health, 404, 401 и 400
logout через одну реплику -> 401 на ['b0db3e40abfe', 'ef44b0d4c0a1']
logout через одну реплику -> 401 на ['48dc392933dc', 'c1b7e1ab5673']
20 x GET /users/me с одним токеном -> реплики {'ef44b0d4c0a1': 10, 'b0db3e40abfe': 10}; это ID запущенных контейнеров api, повторный вход не нужен
20 x GET /users/me с одним токеном -> реплики {'c1b7e1ab5673': 10, '48dc392933dc': 10}; это ID запущенных контейнеров api, повторный вход не нужен
10 x GET /users/me через реплики {'ef44b0d4c0a1': 5, 'b0db3e40abfe': 5}: попаданий в кэш +20, промахов +0 — кэш общий
10 x GET /users/me через реплики {'c1b7e1ab5673': 5, '48dc392933dc': 5}: попаданий в кэш +20, промахов +0 — кэш общий
сообщение записала реплика ef44b0d4c0a1, сразу прочитали ['b0db3e40abfe', 'ef44b0d4c0a1']
сообщение записала реплика c1b7e1ab5673, сразу прочитали ['48dc392933dc', 'c1b7e1ab5673']
с тем же ключом: сначала 400 (пустой текст), потом 201 — ошибка ключ не заняла
@@ -81,10 +83,10 @@ OK
10 одновременных разных тел с одним ключом: 201 x1, 409 x9, в истории 1 сообщение
20 одновременных POST с одним ключом через реплики {'b0db3e40abfe': 10, 'ef44b0d4c0a1': 10}: все 201 с одним id, в истории 1 сообщение
20 одновременных POST с одним ключом через реплики {'48dc392933dc': 10, 'c1b7e1ab5673': 10}: все 201 с одним id, в истории 1 сообщение
повтор: посторонний -> 404, после logout -> 401, после нового входа -> то же сообщение
1 запрос + 4 повтора через реплики ['b0db3e40abfe', 'ef44b0d4c0a1']: 201 и то же сообщение, в истории 1
1 запрос + 4 повтора через реплики ['48dc392933dc', 'c1b7e1ab5673']: 201 и то же сообщение, в истории 1
другой текст с тем же ключом -> 409 conflict, второе сообщение не создано
+2 -2
View File
@@ -1,9 +1,9 @@
python student-tests/worker_crash.py
A. worker_after_objects armed; upload -> 202 (7d0b4994-daec-489f-ab0c-fbad47e60ff5)
A. worker_after_objects armed; upload -> 202 (29951699-589c-4919-8291-a58289f70dff)
the worker crashed after writing objects (restart count 0 -> 1); objects left by the crashed attempt: 3
events: queued(1) -> claimed(1) -> lease_expired(1) -> retry_scheduled(1) -> claimed(2) -> ready(2)
ready at attempt 2; same keys and the same SHA-256 as the crashed attempt wrote: ['crop.jpg', 'optimized.webp', 'thumbnail.jpg']; 3 variant rows
B. worker_after_commit armed; upload -> 202 (d37dd53f-e784-47ba-9351-af5c9b091bd5)
B. worker_after_commit armed; upload -> 202 (50d85920-ab49-4658-9bf8-f61e1ac50181)
events: queued(1) -> claimed(1) -> ready(1) -> duplicate_ignored(1)
the redelivered message found the job ready and was acknowledged without processing
PASS: a worker crash after writing objects but before ack is finished by a retry with the same result; a crash after COMMIT but before ack ends with a no-op redelivery
+6 -6
View File
@@ -1,13 +1,13 @@
python student-tests/worker_outage.py
1. worker stopped: no running worker containers
2. upload -> 202 queued, attachment_id=58fc7ebe-6b35-4894-8af6-aad8f620136a
2. upload -> 202 queued, attachment_id=514906d6-77b8-4dec-a73f-a43670fc65ab
GET -> queued, /content -> 409, /content?variant=thumbnail -> 409
3. message with the queued attachment -> 201 (72038a80-6630-48ce-990a-4c37d5442ea4); text message -> 201 (d2a39236-0930-4973-ac60-f8089e57fc00)
3. message with the queued attachment -> 201 (97507e33-6eca-4009-aa8e-4239ddece625); text message -> 201 (1296cc2b-4850-4695-93bc-07411472f7a7)
4. after 5 s still queued: the API does not resize synchronously
5. job 8006a767-095b-412d-9493-fed8b6382c6d attempt 1: outbox row published at 2026-10-25T18:22:00.036515+00:00 by relay-ef44b0d4c0a1; queues: {'attachments.process': (1, 0), 'attachments.dead': (7, 0)}
5. job 296f84cb-b2cd-49b6-9080-2e460df42764 attempt 1: outbox row published at 2026-10-26T16:37:37.645701+00:00 by relay-c1b7e1ab5673; queues: {'attachments.process': (1, 0), 'attachments.dead': (34, 0)}
6. api replicas restarted (same containers, volumes kept)
broker restarted with volume rabbitmqdata; queues after restart: {'attachments.process': (1, 0), 'attachments.dead': (7, 0)}
7. worker started -> ready after 3.2 s
thumbnail 256×160 JPEG, original SHA-256 unchanged, message 72038a80-6630-48ce-990a-4c37d5442ea4 keeps the attachment; outbox rows for the job: 1 (published once, before the broker restart)
broker restarted with volume rabbitmqdata; queues after restart: {'attachments.process': (1, 0), 'attachments.dead': (34, 0)}
7. worker started -> ready after 3.8 s
thumbnail 256×160 JPEG, original SHA-256 unchanged, message 97507e33-6eca-4009-aa8e-4239ddece625 keeps the attachment; outbox rows for the job: 1 (published once, before the broker restart)
job events: queued(1) -> claimed(1) -> ready(1)
PASS: with the worker down uploads are accepted (202) and wait; the accepted job survives API and broker restarts and becomes ready once the worker is started