forked from mtusi2026/mtusi2026lab7
67 lines
2.1 KiB
Python
67 lines
2.1 KiB
Python
#!/usr/bin/env python3
|
|
"""Verify an upload committed while the publisher is stopped is processed after restart."""
|
|
import hashlib
|
|
import json
|
|
import subprocess
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
sys.path.insert(0, str(ROOT / "tests"))
|
|
from client import Client, arguments, check, run
|
|
|
|
|
|
def compose(*args):
|
|
return subprocess.run(
|
|
["docker", "compose", *args],
|
|
cwd=ROOT,
|
|
check=True,
|
|
capture_output=True,
|
|
text=True,
|
|
)
|
|
|
|
|
|
def main():
|
|
args = arguments("Verify committed attachment outbox intent survives publisher downtime")
|
|
client = Client(args.base_url, args.ca_file)
|
|
alice, _, _, chat = client.bootstrap()
|
|
compose("stop", "publisher")
|
|
try:
|
|
attachment, original = client.attachment(alice, chat)
|
|
check(attachment["status"] == "queued", "upload was not accepted into queued state")
|
|
finally:
|
|
compose("start", "publisher")
|
|
|
|
ready = client.wait_ready(alice, attachment)
|
|
stored_original = client.call(
|
|
"GET",
|
|
"/api/v1/attachments/" + attachment["id"] + "/content",
|
|
actor=alice,
|
|
)["bytes"]
|
|
thumbnail = client.call(
|
|
"GET",
|
|
"/api/v1/attachments/" + attachment["id"] + "/content?variant=thumbnail",
|
|
actor=alice,
|
|
)["bytes"]
|
|
variant = next(item for item in ready["variants"] if item["name"] == "thumbnail")
|
|
check(stored_original == original, "recovered job changed original bytes")
|
|
check(hashlib.sha256(thumbnail).hexdigest() == variant["sha256"], "recovered thumbnail checksum mismatch")
|
|
print(
|
|
json.dumps(
|
|
{
|
|
"result": "PASS",
|
|
"accepted_status_before_publisher_restart": attachment["status"],
|
|
"final_status": ready["status"],
|
|
"attachment_id": attachment["id"],
|
|
"original_sha256": hashlib.sha256(stored_original).hexdigest(),
|
|
"thumbnail_sha256": variant["sha256"],
|
|
"recovered_without_manual_republish": True,
|
|
},
|
|
sort_keys=True,
|
|
)
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
run(main)
|