44 lines
1.8 KiB
Python
44 lines
1.8 KiB
Python
"""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)
|