From d69216785d306c0cb8ca601e2e8b5e471d9b4070 Mon Sep 17 00:00:00 2001 From: Alexey Bodanyuk <144894236+wfa22@users.noreply.github.com> Date: Sat, 28 Nov 2026 15:24:30 +0300 Subject: [PATCH] =?UTF-8?q?collect=5Fevidence:=20=D1=81=D0=B4=D0=B2=D0=B8?= =?UTF-8?q?=D0=B3=20round-robin=20=D0=BC=D0=B5=D0=B6=D0=B4=D1=83=20=D0=BF?= =?UTF-8?q?=D1=80=D0=BE=D0=B3=D0=BE=D0=BD=D0=B0=D0=BC=D0=B8=20failover,=20?= =?UTF-8?q?=D1=80=D0=B5=D0=B6=D0=B8=D0=BC=20--only-failover?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/collect_evidence.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/scripts/collect_evidence.py b/scripts/collect_evidence.py index a292b53..9e00e7a 100644 --- a/scripts/collect_evidence.py +++ b/scripts/collect_evidence.py @@ -13,9 +13,11 @@ import argparse import datetime as dt import json import os +import ssl import subprocess import sys import time +import urllib.request from pathlib import Path ROOT = Path(__file__).resolve().parents[1] @@ -116,6 +118,15 @@ def failover_both() -> None: (EVIDENCE / filename).write_text("# make test-failover: последовательный отказ реплик API\n", encoding="utf-8") code = 0 for attempt in range(1, 6): + # The test stops the replica that served its first message. After a restore HAProxy's + # round robin is in the same position, so the same replica would be hit every time: shift it + # by `attempt - 1` extra requests through the LB (the public test itself is not touched). + for _ in range(attempt - 1): + try: + urllib.request.urlopen("https://localhost:8443/health/live", timeout=5, + context=ssl.create_default_context(cafile=CA)).read() + except OSError: + pass before = {c for c in subprocess.run(["docker", "compose", "ps", "-q", "api"], cwd=ROOT, capture_output=True, text=True, env=ENV).stdout.split()} rc = step(f"failover run {attempt}", filename, @@ -139,8 +150,20 @@ def failover_both() -> None: def main() -> int: parser = argparse.ArgumentParser() parser.add_argument("--skip-student-tests", action="store_true") + parser.add_argument("--only-failover", action="store_true", + help="re-run only the failover series and update its row in SUMMARY.md") args = parser.parse_args() EVIDENCE.mkdir(exist_ok=True) + if args.only_failover: + failover_both() + title, command, code, filename, _ = results[-1] + summary = EVIDENCE / "SUMMARY.md" + row = f"| {title} | `{command}` | {code} | [{filename}]({filename}) | — |" + lines = [row if line.startswith(f"| {title} |") else line + for line in summary.read_text(encoding="utf-8").splitlines()] + summary.write_text("\n".join(lines) + "\n", encoding="utf-8", newline="\n") + print(f"{'PASS' if code == 0 else 'FAIL'} failover series; SUMMARY.md updated") + return code stand_report() step("make check", "check.txt", [PY, "scripts/check_contract.py"]) step("make test (HTTPS, public CA)", "smoke.txt", [PY, "tests/smoke.py", "--base-url", "https://localhost:8443", "--ca-file", CA])