forked from mtusi2026/mtusi2026lab2
ЛР 2: PostgreSQL, сессии, Redis и исследование
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
"""Local Compose test helpers. SQL uses only synthetic identifiers generated by tests."""
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
sys.path.insert(0, str(ROOT / "tests"))
|
||||
from client import Failure, check # noqa: E402
|
||||
|
||||
|
||||
def compose(*args, input_text=None, timeout=40):
|
||||
result = subprocess.run(["docker", "compose", *args], cwd=ROOT, input=input_text,
|
||||
text=True, capture_output=True, timeout=timeout)
|
||||
check(result.returncode == 0, "Compose operation failed (inspect the local stack)")
|
||||
return result.stdout.strip()
|
||||
|
||||
|
||||
def sql(statement, service="postgres", database="messenger", timeout=40):
|
||||
return compose("exec", "-T", service, "psql", "-X", "-U", "messenger",
|
||||
"-d", database, "-v", "ON_ERROR_STOP=1", "-Atq", input_text=statement, timeout=timeout)
|
||||
|
||||
|
||||
def redis(*args):
|
||||
return compose("exec", "-T", "redis", "redis-cli", "--raw", *args)
|
||||
|
||||
|
||||
def ready(client):
|
||||
deadline = time.monotonic() + 45
|
||||
while True:
|
||||
try:
|
||||
client.call("GET", "/health/ready", schema="Health")
|
||||
return
|
||||
except Failure:
|
||||
check(time.monotonic() < deadline, "stack did not recover within 45 seconds")
|
||||
time.sleep(0.5)
|
||||
Reference in New Issue
Block a user