59 lines
1.9 KiB
Python
59 lines
1.9 KiB
Python
"""Real HTTP → worker test of legal 40-million-pixel RGB and alpha images."""
|
|
|
|
import hashlib
|
|
import json
|
|
import subprocess
|
|
import sys
|
|
import time
|
|
from io import BytesIO
|
|
from pathlib import Path
|
|
|
|
from PIL import Image
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "tests"))
|
|
from client import Client
|
|
|
|
c = Client("http://127.0.0.1:8085", timeout=30)
|
|
alice, _, _, chat = c.bootstrap()
|
|
results = []
|
|
for mode, color in (("RGB", (30, 80, 150)), ("RGBA", (30, 80, 150, 100))):
|
|
buffer = BytesIO()
|
|
with Image.new(mode, (10000, 4000), color) as image:
|
|
image.save(buffer, "PNG")
|
|
data = buffer.getvalue()
|
|
start = time.monotonic()
|
|
a = c.call(
|
|
"POST",
|
|
f"/api/v1/chats/{chat['id']}/attachments?filename=boundary.png",
|
|
202,
|
|
actor=alice,
|
|
raw=data,
|
|
headers={"Content-Type": "image/png"},
|
|
schema="Attachment",
|
|
)["json"]
|
|
a = c.wait_ready(alice, a)
|
|
assert a["sha256"] == hashlib.sha256(data).hexdigest()
|
|
assert {v["name"] for v in a["variants"]} == {"thumbnail", "crop", "optimized"}
|
|
results.append(
|
|
{
|
|
"mode": mode,
|
|
"pixels": 40_000_000,
|
|
"size_bytes": len(data),
|
|
"attachment_id": a["id"],
|
|
"seconds_to_ready": round(time.monotonic() - start, 3),
|
|
"status": a["status"],
|
|
}
|
|
)
|
|
cid = subprocess.check_output(["docker", "compose", "ps", "-q", "worker"], text=True).strip()
|
|
state = json.loads(subprocess.check_output(["docker", "inspect", cid], text=True))[0]
|
|
result = {
|
|
"cases": results,
|
|
"worker_memory_limit": state["HostConfig"]["Memory"],
|
|
"worker_oom_killed": state["State"]["OOMKilled"],
|
|
"passed": True,
|
|
"limits": "Child RLIMIT_AS=700MiB, RLIMIT_CPU=15s, wall timeout=20s; this is not a peak RSS measurement.",
|
|
}
|
|
assert not result["worker_oom_killed"]
|
|
Path("evidence/pixel-boundary.json").write_text(json.dumps(result, indent=2))
|
|
print(json.dumps(result, indent=2))
|