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

Reprocess of a queued/processing/failed upload now sources from verified staging instead of the not-yet-written final original, which used to supersede v1 and strand the attachment in queued. PNG uploads now inflate the concatenated IDAT stream (bounded by IHDR dimensions) before acceptance, so a structurally valid PNG whose IDAT is not a zlib stream is rejected with 415 instead of 202.
This commit is contained in:
Vladislav Kunetskiy
2026-10-31 00:41:38 +03:00
parent ecdd91a15b
commit b965350cc9
13 changed files with 311 additions and 44 deletions
+24 -1
View File
@@ -12,7 +12,7 @@ sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'tests'))
sys.path.insert(0, str(Path(__file__).resolve().parent))
from client import Client, Failure, arguments, check, run # noqa: E402
from tests_helpers import ROOT, compose, psql # noqa: E402
from tests_helpers import ROOT, compose, jobctl, psql # noqa: E402
FIXTURE = Path(__file__).resolve().parents[1] / 'tests/fixtures/sample.png'
@@ -97,6 +97,29 @@ def main():
check(body['bytes'] == content, 'original lost across restart')
print('stack restart: ready attachment and original preserved')
# 4. Reprocess of a queued upload while the worker is down. The final
# original has never been written, so pipeline 2 must source from staging;
# pointing at the not-yet-existing final original superseded v1 and left
# the attachment queued forever with v2 failed (source_missing).
compose('stop', 'worker')
try:
pinned, _ = client.attachment(alice, chat)
check(pinned['status'] == 'queued', 'reprocess fixture must be queued')
result = jobctl('reprocess', '-attachment', pinned['id'], '-pipeline', '2')
check('SourceKey' in result.stdout, 'reprocess did not return the created job')
queued2 = client.call('GET', '/api/v1/attachments/' + pinned['id'], actor=alice, schema='Attachment')['json']
check(queued2['status'] == 'queued', 'reprocessed upload is not queued')
print('worker down: reprocess pipeline 2 accepted, upload still queued')
finally:
compose('up', '-d', '--no-deps', 'worker', check=False)
ready2 = client.wait_ready(alice, pinned, wait_seconds=90)
check(psql("select pipeline_version from attachments where id='%s'" % pinned['id']) == '2',
'serving pipeline version is not 2 after reprocess')
check(psql("select status from attachment_jobs where attachment_id='%s' order by pipeline_version" % pinned['id']) == 'superseded\nready',
'old job not superseded or new job not ready')
print('worker up: reprocessed upload reached ready at pipeline 2, v1 superseded')
print('PASS: lab5 async worker/broker durability')