ЛР7 - БВТ2302 - Зюлина - на 3
Skeleton contracts / contracts (pull_request) Blocked by required conditions

This commit is contained in:
2026-11-29 12:55:09 +03:00
parent 20afc2c790
commit 5b8c2a22e1
54 changed files with 2781 additions and 94 deletions
+43
View File
@@ -0,0 +1,43 @@
"""Verify that S3 outages fail readiness/uploads cleanly and recover after restart."""
import subprocess
import time
from pathlib import Path
import sys
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT / "tests"))
from client import Client, arguments, run # noqa: E402
def main():
args = arguments("MinIO outage and recovery checks")
# S3 health checks can spend the configured botocore connect timeout on an
# unreachable service before the API returns the expected JSON 503.
c = Client(args.base_url, args.ca_file, timeout=30)
alice, _bob, _eve, chat = c.bootstrap()
fixture = (ROOT / "tests/fixtures/sample.png").read_bytes()
subprocess.run(["docker", "compose", "--env-file", ".env", "stop", "minio"],
cwd=ROOT, check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
try:
# Nginx may hit its upstream timeout while both replicas are waiting
# for the S3 connect timeout, so 504 is also an expected outage result.
c.call("GET", "/health/ready", [503, 504])
c.call("POST", f"/api/v1/chats/{chat['id']}/attachments?filename=outage.png", [503, 504],
actor=alice, raw=fixture, headers={"Content-Type": "image/png"})
finally:
subprocess.run(["docker", "compose", "--env-file", ".env", "start", "minio"],
cwd=ROOT, check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
deadline = time.monotonic() + 45
while True:
try:
c.call("GET", "/health/ready", schema="Health")
break
except Exception:
if time.monotonic() >= deadline:
raise
time.sleep(0.5)
print("PASS: MinIO outage returned 503/504 for readiness/upload and recovered after service restart")
if __name__ == "__main__":
run(main)
+57
View File
@@ -0,0 +1,57 @@
"""Demonstrate accepted upload recovery while the worker is stopped."""
import hashlib
from pathlib import Path
import subprocess
import sys
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT / "tests"))
from client import Client, check
from image_probe import jpeg_size
def compose(*args):
subprocess.run(["docker", "compose", "--env-file", ".env", *args],
cwd=ROOT, check=True)
def main():
client = Client("http://localhost:8080", timeout=10)
alice, bob, _, chat = client.bootstrap()
print("Created synthetic users and chat", flush=True)
compose("stop", "worker")
print("Stopped worker", flush=True)
try:
attachment, original = client.attachment(alice, chat)
print("Upload returned queued", flush=True)
sent = client.message(alice, chat, "", attachments=[attachment["id"]])["json"]
check(sent["attachment_ids"] == [attachment["id"]], "message did not retain attachment reference")
client.call("GET", "/api/v1/attachments/" + attachment["id"] + "/content",
409, actor=bob)
print("Message linked; content correctly unavailable while queued", flush=True)
# The worker stays stopped while the API and durable broker are restarted.
compose("restart", "api1", "api2", "redis-broker", "lb")
print("Restarted API and broker with worker stopped", flush=True)
compose("start", "worker")
print("Started worker", flush=True)
ready = client.wait_ready(bob, attachment)
original_response = client.call("GET", "/api/v1/attachments/" + attachment["id"] + "/content",
actor=bob)
check(original_response["bytes"] == original, "recovered original bytes changed")
check(hashlib.sha256(original_response["bytes"]).hexdigest() == attachment["sha256"],
"recovered original SHA-256 mismatch")
thumbnail_meta = next(v for v in ready["variants"] if v["name"] == "thumbnail")
thumbnail = client.call("GET", "/api/v1/attachments/" + attachment["id"] +
"/content?variant=thumbnail", actor=bob)
check(thumbnail["headers"].get_content_type() == "image/jpeg", "thumbnail is not JPEG")
check(jpeg_size(thumbnail["bytes"]) == (256, 160), "thumbnail dimensions mismatch")
check(hashlib.sha256(thumbnail["bytes"]).hexdigest() == thumbnail_meta["sha256"],
"thumbnail checksum mismatch")
print("PASS: worker recovery; upload stayed queued through API/broker restart and became ready")
finally:
compose("start", "worker")
if __name__ == "__main__":
main()