forked from mtusi2026/mtusi2026lab5
29 lines
1.5 KiB
Python
29 lines
1.5 KiB
Python
#!/usr/bin/env python3
|
|
"""Битый файл: 5 attempt → failed, error_code=invalid_image."""
|
|
import sys, time
|
|
from pathlib import Path
|
|
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
|
|
from tests.client import Client, check
|
|
from student_tests.common import upload, wait_status, psql, ok, fail
|
|
|
|
def main():
|
|
c = Client()
|
|
a, b, e, ch = c.bootstrap()
|
|
# Заведомо валидный PNG в API (MIME проходит), но worker получит
|
|
# битый заголовок, если подменить staging — здесь проверяем
|
|
# реалистичный сценарий: JPEG с обрезанным хвостом.
|
|
content = (Path('tests/fixtures/sample.png')).read_bytes()[:-20]
|
|
att = upload(c, a, ch, content)
|
|
# API пропустит (DecodeConfig проходит), worker упадёт на Decode.
|
|
att = wait_status(c, a, att['id'], 'failed', seconds=180)
|
|
check(att.get('error_code') == 'invalid_image', 'unexpected error_code: %s' % att.get('error_code'))
|
|
attempts = int(psql("SELECT attempt FROM attachment_jobs WHERE attachment_id='%s'" % att['id']))
|
|
# invalid_image — постоянная ошибка, worker не должен ретраить.
|
|
check(attempts == 1, 'permanent error must not be retried: attempt=%d' % attempts)
|
|
ok('failed immediately (attempt=1), error_code=invalid_image — permanent, not retried')
|
|
|
|
if __name__ == '__main__':
|
|
try:
|
|
main()
|
|
except Exception as exc:
|
|
fail(str(exc)) |