"""Accepted queued upload survives worker stop; real broker redelivery and dedupe.""" from pathlib import Path import subprocess import sys import time ROOT=Path(__file__).resolve().parents[1] sys.path.insert(0,str(ROOT/'tests'));sys.path.insert(0,str(ROOT/'scripts')) from client import Client from manage import env def compose(*args):subprocess.run(['docker','compose',*args],cwd=ROOT,check=True) def main(): client=Client('https://localhost:'+env()['HTTPS_PORT'],str(ROOT/'secrets/ca.crt')) alice,bob,eve,chat=client.bootstrap() try: compose('stop','-t','5','worker') attachment,content=client.attachment(alice,chat) assert attachment['status']=='queued' compose('run','--rm','verifier','python','/checks/redelivery.py','redeliver') finally: compose('start','worker') ready=client.wait_ready(alice,attachment) assert client.call('GET','/api/v1/attachments/'+ready['id']+'/content',actor=bob)['bytes']==content assert len(ready['variants'])==1 and ready['variants'][0]['name']=='thumbnail' compose('run','--rm','verifier','python','/checks/redelivery.py','duplicate',ready['id']) time.sleep(3) after=client.call('GET','/api/v1/attachments/'+ready['id'],actor=bob,schema='Attachment')['json'] assert after==ready print('PASS accepted202 during worker stop -> ready with exact original/one thumbnail; no-ack redelivery and completed-job duplicate did not duplicate effects') if __name__=='__main__':main()