Files
2026-11-16 20:30:12 +03:00

35 lines
1.6 KiB
Python

#!/usr/bin/env python3
"""Повторный XADD того же job_id не создаёт дублей вариантов."""
import json, subprocess, 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, docker, ok, fail
def main():
c = Client()
a, b, e, ch = c.bootstrap()
content = Path('tests/fixtures/sample.png').read_bytes()
att = upload(c, a, ch, content)
att = wait_status(c, a, att['id'], 'ready')
before = psql("SELECT count(*) FROM attachment_variants WHERE attachment_id='%s'" % att['id'])
check(before == '3', 'expected 3 variants, got %s' % before)
job = psql("SELECT job_id FROM attachment_jobs WHERE attachment_id='%s'" % att['id'])
payload = json.dumps({
"schema_version": 1, "job_id": job, "type": "attachment.process.v1",
"attachment_id": att['id'], "pipeline_version": 1, "attempt": 1,
"created_at": "2026-01-01T00:00:00Z",
})
# Повторная доставка через Redis CLI.
docker('exec', '-T', 'redis', 'redis-cli', 'XADD', 'attachment.jobs', '*', 'payload', payload)
time.sleep(5)
after = psql("SELECT count(*) FROM attachment_variants WHERE attachment_id='%s'" % att['id'])
check(after == '3', 'redelivery created duplicate variants: %s' % after)
ok('redelivery is no-op (still 3 non-original variants; original via object_key)')
if __name__ == '__main__':
try:
main()
except Exception as exc:
fail(str(exc))