# Доказывает: проверки отказов с числами (`pytest -m fault -rP`) на отдельном
#   стенде vladimirceva-lab6-failures с кодом уровней 3–4 (телеметрия включена):
#   окна отказа PostgreSQL, Valkey, S3 (503 / 200 / 429 / 400 с временем),
#   уборка и сверка, pipeline — потеря брокера, relay, worker в трёх точках
#   краха, исчерпание попыток и replay, staging удалён после ready.
# Дата: 2026-11-15, 22:24 UTC; длительность 500 с (pytest — 461,73 с).
# Окружение: macOS 26.7.1, Docker 29.9.2, Compose 5.6.1, Python хоста 3.11.9
#   (pytest в uv-окружении, Python 3.13.15).
# Стенд: отдельный (make failure-checks), удаляется самим прогоном.
# Код: src_sha256 81c47ffceeb40acc6f333a9265a15480b3e13e2cb53b2e2229e5fa7391bd0b7a
# Повторить: make failure-checks FAULT_ARGS=-rP
# `...` — пропущены строки сборки и подъёма стенда и хвосты длинных строк
#   (словарь сверки, поля заданий).

$ make failure-checks FAULT_ARGS=-rP
[failures] project=vladimirceva-lab6-failures
...
[failures] pytest -m fault
collected 212 items / 178 deselected / 34 selected

student-tests/test_failures.py ........................                  [ 70%]
student-tests/test_pipeline.py ..........                                [100%]

test_database_stopped_and_back:
postgres stopped: POST message -> 503 in 0.009s
test_frozen_database_and_exhausted_pool:
postgres paused: first request -> 503 in 4.01s, second (pool of 1 busy) -> 503 in 1.01s
test_readiness_without_database:
postgres stopped: /health/ready -> 503 in 0.014s
test_valkey_stopped_is_bypassed:
valkey stopped: GET chat -> 200 in 0.207s, POST message -> 201 in 0.006s
test_valkey_paused_costs_one_timeout:
valkey paused: baseline 0.002s, first read 0.206s, second read 0.003s
test_upload_with_s3_stopped:
s3 stopped: upload -> 503 in 0.048s
test_upload_and_download_with_s3_paused:
s3 paused: upload -> 503 in 5.02s, download -> 503 in 5.02s
test_ready_failure_compensates_and_cleaner_removes_row:
queue failed: staging compensated at once, row removed after 24.7s
test_kill_between_put_and_ready:
killed between PUT and queueing: client got ['RemoteProtocolError']
cleaner removed row and object 19.7s after the kill check
test_upload_slots_busy_is_429:
slots busy: third upload -> 429 in 0.018s (Too many uploads in progress, retry later)
test_upload_body_timeout_is_400:
slow body: -> 400 in 3.01s (Upload body was not received in time)
test_reconcile_finds_and_fixes_both_sides:
dry-run: {... 'orphan_object', 'size_mismatch', 'missing_object' ...}
after fixes:  apply=false strategy=batch deep=false rate=2000 listed_objects=28 checked_rows=7 fresh_objects=0 fresh_rows=0 lost_known=1 found_orphan_object=0 ...
test_reconcile_apply_under_uploads:
reconcile --apply passes: [0, 0, 0]; uploads: 1902; errors: []
test_worker_down_defense_flow:
after restarts: {'state': 'ready', 'attempt': 1, 'attempt_base': 0, 'published': True, 'leased': False, 'last_error': '-'}
test_broker_restart_keeps_published_job:
after broker restart: message visible in queue after 0.6s
test_relay_down_keeps_intent_in_outbox:
relay back: ready after 4.1s, {'state': 'ready', 'attempt': 1, 'attempt_base': 0, 'published': True, 'leased': False, 'last_error': '-'}
test_relay_crash_after_confirm:
faulty relay exit=137, job={'state': 'queued', 'attempt': 0, 'attempt_base': 0, 'published': False, 'leased': False, 'last_error': '-'}
test_worker_crash_after_objects_before_commit:
faulty worker exit=137, objects=['staging', 'original', 'thumbnail', 'crop', 'optimized'], job={'state': 'processing', 'attempt': 1, ...}
after lease: ready in 12.9s, {'state': 'ready', 'attempt': 2, 'attempt_base': 0, 'published': True, 'leased': False, 'last_error': '-'}
test_worker_crash_after_commit_before_ack:
redelivery after commit: {'state': 'ready', 'attempt': 1, 'attempt_base': 0, 'published': True, 'leased': False, 'last_error': '-'}, queue=1 0
test_transient_errors_exhaust_then_replay:
exhausted: retry_exhausted {'state': 'failed', 'attempt': 3, 'attempt_base': 0, 'published': True, 'leased': False, 'last_error': 's3_read'}
test_staging_is_removed_after_ready:
staging removed 0.9s after ready; left: ['original', 'thumbnail', 'crop', 'optimized']
========== 34 passed, 178 deselected, 1 warning in 461.73s (0:07:41) ===========
[failures] cleanup
[failures] results: {'fault': 0}

# Итог: 34 passed, results {'fault': 0}. PostgreSQL недоступен — 503 за 0,01 с,
# заморожен — 503 за 4,01 с; S3 остановлен — 503 за 0,05 с; S3 заморожен — 503
# за 5,02 с; Valkey остановлен — чтение 200 в обход кэша; очередь: после краха
# worker до коммита — ready со 2-й попытки через 12,9 с (аренда), после коммита
# до ack — повторная доставка без дубля, исчерпание — failed/retry_exhausted
# (3 попытки); сверка под нагрузкой — 3 прохода `--apply`, коды 0, 1902 загрузки,
# ошибок нет.
