#!/usr/bin/env python3 """Replay failed → снова queued.""" import sys 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() # Форсим failed (битый файл проходит DecodeConfig, но не Decode). content = Path('tests/fixtures/sample.png').read_bytes()[:-20] att = upload(c, a, ch, content) att = wait_status(c, a, att['id'], 'failed', seconds=180) ok('failed reached') c.call('POST', '/api/v1/attachments/' + att['id'] + '/replay', 202, actor=a) st = psql("SELECT status FROM attachment_jobs WHERE attachment_id='%s'" % att['id']) check(st == 'queued', 'after replay expected queued, got %s' % st) ok('replay -> queued') # Replay дал одну новую попытку; ошибка permanent, поэтому снова failed при attempt=1. att = wait_status(c, a, att['id'], 'failed', seconds=180) atts = int(psql("SELECT attempt FROM attachment_jobs WHERE attachment_id='%s'" % att['id'])) check(atts == 1, 'after replay: permanent error must fail at attempt=1, got %d' % atts) ok('replay reset attempt to 1; permanent error failed again — not retried') if __name__ == '__main__': try: main() except Exception as exc: fail(str(exc))