feat: add checks and limits for 4 grade

This commit is contained in:
TAskMAster339
2026-10-10 14:13:32 +03:00
parent 771951cad7
commit 6892af8842
8 changed files with 402 additions and 1 deletions
+16
View File
@@ -6,6 +6,8 @@ import time
import uuid
from pathlib import Path
from rolling_update import identity, stats
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT / "tests"))
from client import Client, Failure, arguments, check, run
@@ -46,16 +48,21 @@ def main():
confirmed_text = "Before failure " + confirmed_key
original = c.message(alice, chat, confirmed_text, key=confirmed_key)["json"]
env = dict(os.environ, TARGET_INSTANCE_ID=target)
addresses = {network["IPAddress"] for network in identity(container)["networks"].values()}
slot = next(row["svname"] for row in stats() if row["addr"].split(":")[0] in addresses)
started = time.monotonic()
proc = subprocess.Popen([str(ROOT / "scripts" / "stop-one.sh")], cwd=ROOT, env=env,
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
successes, last_instances = [], []
write_errors = read_errors = reads = 0
first_write = first_read = None
excluded = None
key = uuid.uuid4().hex
try:
while time.monotonic() - started < 15:
check(proc.poll() in (None, 0), "stop-one hook failed")
if excluded is None and any(row["svname"] == slot and not row["status"].startswith("UP") for row in stats()):
excluded = time.monotonic() - started
try:
result = c.message(alice, chat, "During failure " + key, key=key)
successes.append(result["json"])
@@ -74,10 +81,12 @@ def main():
except Failure:
read_errors += 1
time.sleep(0.1)
elapsed = time.monotonic() - started
check(proc.poll() == 0, "stop-one hook did not finish")
check(inspect(container)[1] == "exited", "target container did not stay stopped")
check(first_write is not None and first_write <= 10, "writes did not recover within 10 seconds")
check(first_read is not None and first_read <= 10, "reads did not recover within 10 seconds")
check(excluded is not None and excluded <= 6, "HAProxy did not exclude stopped backend within the 6-second budget")
check(len(last_instances) >= 5 and target not in last_instances[-5:], "stopped replica still serves responses")
check(c.message(alice, chat, confirmed_text, key=confirmed_key)["json"] == original,
"replay after switching replicas changed a confirmed message")
@@ -88,6 +97,11 @@ def main():
record = {"stopped_instance": target, "container_state": "exited", "successful_writes": len(successes),
"successful_reads": reads, "write_errors": write_errors, "read_errors": read_errors,
"first_write_seconds": round(first_write, 3), "first_read_seconds": round(first_read, 3)}
record.update(elapsed_seconds=round(elapsed, 3),
lb_exclusion_seconds=round(excluded, 3),
successful_rps=round((len(successes) + reads) / elapsed, 3),
attempted_rps=round((len(successes) + reads + write_errors + read_errors) / elapsed, 3),
workload="one sequential writer and reader, 100ms pause; not a capacity benchmark")
records.append(record)
print(json.dumps(record), flush=True)
finally:
@@ -95,6 +109,8 @@ def main():
proc.terminate()
proc.wait(timeout=5)
restore()
ROOT.joinpath(".memory/grade4").mkdir(parents=True, exist_ok=True)
ROOT.joinpath(".memory/grade4/failover.json").write_text(json.dumps(records, indent=2) + "\n")
print("PASS: each API replica stopped in turn; reads, writes, sessions and confirmed messages preserved")