test: verify persistence, replica failover and queued upload recovery

This commit is contained in:
2026-11-30 16:36:14 +03:00
parent c0576a2dee
commit 1743870de7
6 changed files with 113 additions and 0 deletions
+49
View File
@@ -0,0 +1,49 @@
"""Check that a queued upload survives restarting API and RabbitMQ."""
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, Failure, arguments, check, run
def compose(*args):
subprocess.run(["docker", "compose", *args], cwd=ROOT, check=True)
def main():
args = arguments(__doc__)
client = Client(args.base_url, args.ca_file)
owner = client.user("queue")
chat = client.call("POST", "/api/v1/chats", 201, actor=owner, body={
"title": "Queue restart", "member_ids": [owner["id"]],
}, schema="Chat")["json"]
compose("stop", "-t", "5", "worker")
try:
attachment, original = client.attachment(owner, chat)
content_path = "/api/v1/attachments/" + attachment["id"] + "/content"
client.call("GET", content_path, 409, actor=owner)
compose("restart", "-t", "5", "api", "rabbitmq")
finally:
compose("start", "worker")
deadline = time.monotonic() + 60
while True:
try:
client.call("GET", "/health/ready", schema="Health")
break
except Failure:
check(time.monotonic() < deadline, "API did not recover after restart")
time.sleep(0.5)
client.wait_ready(owner, attachment)
restored = client.call("GET", content_path, 200, actor=owner)["bytes"]
check(restored == original, "Recovered attachment differs from upload")
print("PASS: queued upload survived API and RabbitMQ restart with worker stopped")
if __name__ == "__main__":
run(main)