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

41 lines
1.7 KiB
Python

#!/usr/bin/env python3
"""kill -9 worker после S3 write до ack → повтор не создаёт дублей."""
import sys, time, signal
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, png_bytes
def main():
c = Client()
a, b, e, ch = c.bootstrap()
content = png_bytes(4000, 4000)
# Сначала готовим staging+job, но без запуска worker’а.
docker('stop', 'worker')
att = upload(c, a, ch, content)
# Запускаем worker — он возьмёт processing и, скорее всего, быстро закончит.
docker('start', 'worker')
# Ловим момент processing и убиваем процесс.
deadline = time.monotonic() + 30
while time.monotonic() < deadline:
st = psql("SELECT status FROM attachment_jobs WHERE attachment_id='%s'" % att['id'])
if st == 'processing':
break
time.sleep(0.1)
docker('kill', '-s', 'SIGKILL', 'worker')
ok('worker killed during processing')
# После lease (60s) + reaper (30s) job должна снова стать queued.
time.sleep(100)
docker('start', 'worker')
att = wait_status(c, a, att['id'], 'ready', seconds=120)
n = int(psql("SELECT count(*) FROM attachment_variants WHERE attachment_id='%s'" % att['id']))
check(n == 3, 'expected exactly 3 variants, got %d' % n)
ok('recovery produced exactly 3 non-original variants, no duplicates (original in object_key)')
if __name__ == '__main__':
try:
main()
except Exception as exc:
fail(str(exc))