collect_evidence: сдвиг round-robin между прогонами failover, режим --only-failover
This commit is contained in:
@@ -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])
|
||||
|
||||
Reference in New Issue
Block a user