fix(lab4): preserve error contract and verify storage consistency

This commit is contained in:
kolya5544
2026-11-11 18:25:57 +03:00
parent f875e2977f
commit 0150b91ec0
18 changed files with 1051 additions and 35 deletions
+12 -1
View File
@@ -28,7 +28,8 @@ PROJECT = "mtusi-lab4"
def sh(*args, env=None):
return subprocess.run(args, cwd=ROOT, capture_output=True, text=True, env=dict(os.environ, **(env or {}))).stdout.strip()
return subprocess.run(args, cwd=ROOT, capture_output=True, text=True, check=True,
env=dict(os.environ, **(env or {}))).stdout.strip()
def noisy_png(side, seed):
@@ -54,6 +55,8 @@ def set_api(concurrency, replicas):
if len(ids) == replicas and all(sh("docker", "inspect", "-f", "{{.State.Health.Status}}", i) == "healthy" for i in ids):
break
time.sleep(1)
else:
raise RuntimeError("API replicas did not become healthy within 90 seconds")
time.sleep(6)
@@ -99,6 +102,9 @@ async def main(args):
for conc in args.concurrency:
set_api(conc, 1)
cid = api_containers()[0]
limits = json.loads(sh("docker", "inspect", "-f",
'{"memory_bytes":{{.HostConfig.Memory}},"nano_cpus":{{.HostConfig.NanoCpus}}}', cid))
assert limits == {"memory_bytes": 256 * 1024 * 1024, "nano_cpus": 1000000000}, limits
async with aiohttp.ClientSession() as s:
uid, token = await register(s)
async with s.post(BASE + "/api/v1/chats", json={"title": "mem", "member_ids": [uid]}, headers={"Authorization": "Bearer " + token}) as r:
@@ -120,6 +126,7 @@ async def main(args):
intact += 1
oom = sh("docker", "inspect", "-f", "{{.State.OOMKilled}}", cid)
entry = {"UPLOAD_CONCURRENCY": conc, "statuses": statuses, "wall_seconds": round(wall, 2), "peak_rss_mib": peak,
"resource_limits": limits,
"rss_before_mib": baseline_hwm, "rss_after_mib": rss, "oom_killed": oom,
"accepted_files_intact": "%d/%d" % (intact, statuses.get("201", 0)),
"p50_s": round(ok_lat[len(ok_lat) // 2], 2) if ok_lat else None, "max_s": round(ok_lat[-1], 2) if ok_lat else None}
@@ -128,6 +135,10 @@ async def main(args):
set_api(4, 2)
with open(os.path.join(args.out, "upload_memory.json"), "w", encoding="utf-8") as fh:
json.dump(report, fh, ensure_ascii=False, indent=2)
for entry in report["runs"]:
assert entry["statuses"] == {"201": args.clients}, entry
assert entry["accepted_files_intact"] == "%d/%d" % (args.clients, args.clients), entry
assert entry["oom_killed"] == "false" and 0 < entry["peak_rss_mib"] < 256, entry
if __name__ == "__main__":