forked from mtusi2026/mtusi2026lab2
48 lines
1.9 KiB
Python
48 lines
1.9 KiB
Python
"""Windows-compatible persistence acceptance test for Docker Compose."""
|
|
import subprocess
|
|
import sys
|
|
import time
|
|
from pathlib import Path
|
|
from client import Client, arguments, check, run
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
|
|
def main():
|
|
args = arguments("Windows-compatible PostgreSQL/session persistence scenario")
|
|
c = Client(args.base_url, args.ca_file, timeout=5)
|
|
alice, bob, eve, chat = c.bootstrap()
|
|
original = c.message(alice, chat, "Проверка сохранности после рестарта")["json"]
|
|
token = alice["token"]
|
|
|
|
hook = ROOT / "scripts" / "restart.ps1"
|
|
check(hook.is_file(), "scripts/restart.ps1 is missing")
|
|
result = subprocess.run(
|
|
["powershell.exe", "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", str(hook)],
|
|
cwd=str(ROOT), timeout=110, capture_output=True, text=True
|
|
)
|
|
if result.returncode:
|
|
print(result.stdout)
|
|
print(result.stderr, file=sys.stderr)
|
|
check(False, "PowerShell restart hook failed")
|
|
|
|
deadline = time.monotonic() + 90
|
|
while True:
|
|
try:
|
|
c.call("GET", "/health/ready", schema="Health")
|
|
break
|
|
except Exception:
|
|
check(time.monotonic() < deadline, "API did not recover")
|
|
time.sleep(1)
|
|
|
|
same_actor = {"id": alice["id"], "token": token}
|
|
me = c.call("GET", "/api/v1/users/me", actor=same_actor, schema="User")["json"]
|
|
check(me["id"] == alice["id"], "existing session did not survive restart")
|
|
history = c.call("GET", "/api/v1/chats/" + chat["id"] + "/messages?limit=100",
|
|
actor={"id": bob["id"], "token": bob["token"]},
|
|
schema="MessagePage")["json"]
|
|
check(original in history["items"], "confirmed message did not survive restart")
|
|
print("PASS: PostgreSQL data and existing Bearer session survived API + PostgreSQL + Redis restart.")
|
|
|
|
if __name__ == "__main__":
|
|
run(main)
|