forked from mtusi2026/mtusi2026lab3
feat:report
This commit is contained in:
+22
-20
@@ -1,11 +1,9 @@
|
||||
"""Общие утилиты для студенческих тестов."""
|
||||
import base64
|
||||
"""Общие утилиты для моих тестов."""
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
import uuid
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
@@ -15,21 +13,14 @@ from client import Client, Failure, check # noqa: E402
|
||||
|
||||
BASE_URL = os.environ.get('BASE_URL', 'http://localhost:8080')
|
||||
COMPOSE_CMD = os.environ.get('COMPOSE_CMD', 'docker compose')
|
||||
COMPOSE_PROJECT = os.environ.get('COMPOSE_PROJECT', '')
|
||||
|
||||
|
||||
def compose(*args, timeout=120, check_rc=True):
|
||||
"""Вызов docker compose. Возвращает CompletedProcess."""
|
||||
cmd = COMPOSE_CMD.split()
|
||||
if COMPOSE_PROJECT:
|
||||
cmd += ['-p', COMPOSE_PROJECT]
|
||||
cmd += list(args)
|
||||
proc = subprocess.run(
|
||||
cmd, cwd=str(ROOT), capture_output=True, text=True, timeout=timeout)
|
||||
def compose(*args, timeout=180, check_rc=True):
|
||||
cmd = COMPOSE_CMD.split() + list(args)
|
||||
proc = subprocess.run(cmd, cwd=str(ROOT), capture_output=True, text=True, timeout=timeout)
|
||||
if check_rc and proc.returncode != 0:
|
||||
raise Failure(
|
||||
'compose %s failed rc=%d\nstdout=%s\nstderr=%s'
|
||||
% (' '.join(args), proc.returncode, proc.stdout[-2000:], proc.stderr[-2000:]))
|
||||
raise Failure('compose %s failed rc=%d\nstderr=%s'
|
||||
% (' '.join(args), proc.returncode, proc.stderr[-1000:]))
|
||||
return proc
|
||||
|
||||
|
||||
@@ -46,7 +37,6 @@ def wait_ready(deadline_seconds=90):
|
||||
|
||||
|
||||
def observe_instances(c, actor, n=40):
|
||||
"""Собираем X-Instance-Id через /users/me."""
|
||||
seen = {}
|
||||
for _ in range(n):
|
||||
r = c.call('GET', '/api/v1/users/me', actor=actor, schema='User')
|
||||
@@ -56,11 +46,23 @@ def observe_instances(c, actor, n=40):
|
||||
return seen
|
||||
|
||||
|
||||
def run_file(path, *args, timeout=180):
|
||||
def stop_one(target_instance_id):
|
||||
env = {**os.environ, 'TARGET_INSTANCE_ID': target_instance_id}
|
||||
proc = subprocess.run(
|
||||
[sys.executable, str(path), *args],
|
||||
cwd=str(ROOT), capture_output=True, text=True, timeout=timeout)
|
||||
return proc
|
||||
[str(ROOT / 'scripts/stop-one.sh')],
|
||||
cwd=str(ROOT), env=env, capture_output=True, text=True, timeout=30)
|
||||
check(proc.returncode == 0,
|
||||
'stop-one.sh для %s упал: %s' % (target_instance_id, proc.stderr[-500:]))
|
||||
|
||||
|
||||
def restore_api():
|
||||
"""Запускает все остановленные контейнеры сервиса api."""
|
||||
proc = subprocess.run(
|
||||
[str(ROOT / 'scripts/restore-api.sh')],
|
||||
cwd=str(ROOT), capture_output=True, text=True, timeout=90)
|
||||
check(proc.returncode == 0,
|
||||
'restore-api.sh упал: %s' % proc.stderr[-500:])
|
||||
wait_ready(60)
|
||||
|
||||
|
||||
def print_pass(name, extra=''):
|
||||
|
||||
Reference in New Issue
Block a user