реализация 4 лабы

This commit is contained in:
Ванек
2026-11-05 19:30:42 +03:00
parent 5c9b3e206a
commit c43d3490a0
26 changed files with 3835 additions and 74 deletions
+10 -8
View File
@@ -16,6 +16,7 @@ from uuid import uuid4
from helpers import Client, ROOT
from client import Failure
from resilience import history
from attachment_checks import run_checks
def docker(*args):
@@ -26,7 +27,7 @@ def main():
with socket.socket() as sock:
sock.bind(("127.0.0.1", 0))
port = sock.getsockname()[1]
project = "lab3-check-" + uuid4().hex[:10]
project = "lab4-check-" + uuid4().hex[:10]
base = f"http://127.0.0.1:{port}"
env = dict(os.environ, COMPOSE_PROJECT_NAME=project, HOST_PORT=str(port),
API_REPLICAS="2", SESSION_TTL_SECONDS="3600", BASE_URL=base)
@@ -202,15 +203,16 @@ time.sleep(30)
assert all(m["Destination"].startswith("/run/secrets/") for m in info["Mounts"])
print("PASS: 2 real API containers, CPU/RAM limits, API non-root and no public ports; only LB published", flush=True)
subprocess.run([str(ROOT / "scripts/check.sh")], cwd=ROOT, env=env, check=True, timeout=240)
result["api_tests"] = "public smoke + 28 student tests passed"
result["api_tests"] = "public smoke + student unittest suite passed"
subprocess.run([str(ROOT / "scripts/demo.sh")], cwd=ROOT, env=env, check=True, stdout=subprocess.DEVNULL, timeout=30)
assert sql("SELECT count(*) FROM schema_migrations") == "2"
assert sql("SELECT count(*) FROM schema_migrations") == "3"
count = sql("SELECT count(*) FROM messages")
for _ in range(2):
compose("run", "--rm", "migrate")
assert sql("SELECT count(*) FROM schema_migrations") == "2"
assert sql("SELECT count(*) FROM schema_migrations") == "3"
assert sql("SELECT count(*) FROM messages") == count
print("PASS: migrations only in one-shot service; repeated execution preserves data", flush=True)
result["attachments"] = run_checks(base, env, compose, apis, script, sql)
replay_client = Client(base)
replay_actor, _, _, replay_chat = replay_client.bootstrap()
@@ -225,14 +227,14 @@ time.sleep(30)
assert replay_client.message(replay_actor, replay_chat, "Повтор после рестарта", key=replay_key)["json"] == saved_message
result["persistence"] = {"before": list(before.values()), "after": list(after.values()), "passed": True,
"idempotency_replay_after_restart": True}
print("PASS: both API, LB, PostgreSQL, Valkey actually restarted; session and confirmed data preserved", flush=True)
print("PASS: both API, LB, PostgreSQL, Valkey, S3 and cleaner actually restarted; data and session preserved", flush=True)
check_shutdown()
dependency_client = Client(base)
actor = dependency_client.user("deps")
result["dependency_readiness"] = []
for dependency in ("valkey", "postgres"):
for dependency in ("valkey", "postgres", "s3"):
try:
compose("stop", "--timeout", "8", dependency)
probe_id = apis()[0]["Id"]
@@ -302,9 +304,9 @@ time.sleep(30)
result["rolling_update"] = load_action("sequential API replacement", replace)
result["passed"] = True
print("PASS: all lab3 grade-4 checks completed", flush=True)
print("PASS: all lab4 grade-4 checks completed", flush=True)
finally:
output = ROOT / "evidence" / "lab3-checks.json"
output = ROOT / "evidence" / "lab4-checks.json"
output.write_text(json.dumps(result, ensure_ascii=False, indent=2) + "\n")
compose("down", "--volumes", "--timeout", "8")
print("Removed only temporary test containers and volumes:", project, flush=True)