import os import subprocess import sys import time from pathlib import Path root = Path(__file__).resolve().parents[1] sys.path.insert(0,str(root/"tests")) from client import Client, arguments, check os.chdir(root) args = arguments("Verify durable upload with the worker offline") c = Client(args.base_url,args.ca_file) alice,bob,_,chat = c.bootstrap() def compose(*args): subprocess.run(["docker","compose",*args],check=True) compose("stop","worker") try: att,original = c.attachment(alice,chat) msg = c.message(alice,chat,"",attachments=[att["id"]])["json"] check(msg["attachment_ids"]==[att["id"]],"link lost") compose("restart","api","api2","queue") finally: compose("start","worker") for _ in range(90): try: c.call("GET","/health/ready") break except AssertionError: time.sleep(1) ready = c.wait_ready(bob,att) check(ready["variants"][0]["name"]=="thumbnail","missing thumbnail") result = c.call("GET","/api/v1/attachments/"+att["id"]+"/content",actor=bob) check(result["bytes"]==original,"original mismatch") print("PASS: worker offline -> durable upload -> message -> API and broker restart -> thumbnail ready; original matched")