lab5: исправления по ревью

Concurrent complete no longer deletes the shared verified source; admission is atomic and covers pending presign rows; relay reconciles queued jobs lost to dead-lettering; failed staging is protected until failed_retention; timestamps normalized to UTC; reprocess prefers the durable original and keeps job->attachment lock order; heartbeat errors no longer burn attempts; confirm timeout enforced; pinned images and sanitized health responses.
This commit is contained in:
Vladislav Kunetskiy
2026-10-30 23:13:44 +03:00
parent 4bdcac3dfa
commit 9d7a0acb5a
40 changed files with 592 additions and 521 deletions
+16 -1
View File
@@ -17,6 +17,17 @@ from tests_helpers import ROOT, compose, psql # noqa: E402
FIXTURE = Path(__file__).resolve().parents[1] / 'tests/fixtures/sample.png'
def wait_api_ready(client, timeout=60):
deadline = time.monotonic() + timeout
while time.monotonic() < deadline:
try:
client.call('GET', '/health/ready', schema='Health')
return
except Failure:
time.sleep(0.2)
raise Failure('API did not become ready after restart')
def wait_state(client, actor, attachment, expected, timeout=60):
deadline = time.monotonic() + timeout
while time.monotonic() < deadline:
@@ -46,7 +57,10 @@ def main():
time.sleep(2)
still = client.call('GET', '/api/v1/attachments/' + attached['id'], actor=alice, schema='Attachment')['json']
check(still['status'] == 'queued', 'worker stopped but job was processed synchronously')
print('worker down: 202 queued, content 409, queued attachment linked')
# The README demo restarts the API after the 202 and before the worker.
compose('restart', 'api')
wait_api_ready(client)
print('worker down: 202 queued, content 409, queued attachment linked, API restarted')
finally:
compose('up', '-d', '--no-deps', 'worker', check=False)
@@ -76,6 +90,7 @@ def main():
# 3. A full stack restart with volumes keeps ready data and the worker path.
compose('restart', 'api', 'worker', 'relay')
wait_api_ready(client)
recovered = client.call('GET', '/api/v1/attachments/' + ready['id'], actor=bob, schema='Attachment')['json']
check(recovered['status'] == 'ready', 'ready attachment lost across restart')
body = client.call('GET', '/api/v1/attachments/' + ready['id'] + '/content', actor=bob)
+10 -1
View File
@@ -110,6 +110,8 @@ def scenario_transient_exhaustion(client, alice, chat):
attached, _ = client.attachment(alice, chat)
jid = job_id(attached['id'])
dlq_before = queue_messages('attachment.process.dead')
worker_with(
FAULTS_ENABLED='1', FAULT_TARGET_JOB=jid, FAULT_WORKER_FAIL='transient',
PROCESSING_RETRY_BASE='100ms', PROCESSING_RETRY_CAP='500ms',
@@ -120,7 +122,14 @@ def scenario_transient_exhaustion(client, alice, chat):
events = psql("select event || ':' || coalesce(attempt,0) from attachment_job_events where job_id='%s' order by id" % jid)
check(events.count('retried:') == 4, 'expected four managed retries: ' + events)
check(events.count('failed:') == 1, 'expected one terminal failure: ' + events)
check(queue_messages('attachment.process.dead') >= 1, 'terminal failure did not reach the DLQ')
deadline = time.monotonic() + 15
while time.monotonic() < deadline:
if queue_messages('attachment.process.dead') >= dlq_before + 1:
break
time.sleep(0.2)
check(queue_messages('attachment.process.dead') >= dlq_before + 1,
'terminal failure did not add a DLQ message')
print('transient exhaustion: attempts=5, retry_exhausted, four retries, DLQ message present')
reset_worker()