test: fail fault checks when the stand postgres crashes
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -8,6 +8,9 @@
|
||||
идемпотентности 2 с, пул из одного соединения);
|
||||
- прогоняет тесты с маркером `fault` (`pytest -m fault`), передав им hook
|
||||
`student-tests/fault_hook.py`;
|
||||
- после тестов читает журнал PostgreSQL стенда: печатает сводку и падает
|
||||
на признаках аварийного перезапуска (решение 12 design change
|
||||
`fix-known-issues`);
|
||||
- удаляет стенд вместе с volume при любом исходе, в том числе по Ctrl+C.
|
||||
|
||||
Рабочий стенд, его база и кэш не затрагиваются. Только stdlib. Решения
|
||||
@@ -38,6 +41,16 @@ FAULT_HOOK = ROOT / "student-tests" / "fault_hook.py"
|
||||
PROJECT_SUFFIX = "-failures"
|
||||
READY_TIMEOUT_S = 60
|
||||
LOG_TAIL_LINES = 50
|
||||
# признаки аварийного перезапуска PostgreSQL: postmaster счёл аварией выход
|
||||
# неизвестного потомка, завершил все процессы и восстанавливается. Штатные
|
||||
# stop / start дают «database system was shut down», обрыв backend — FATAL
|
||||
CRASH_MARKERS = (
|
||||
"untracked child process",
|
||||
"terminating any other active server processes",
|
||||
"reinitializing",
|
||||
"automatic recovery in progress",
|
||||
)
|
||||
CRASH_LINES_MAX = 20
|
||||
# «тесный» API: короткие сроки сессии и ключа идемпотентности, пул из
|
||||
# одного соединения
|
||||
TIGHT_ENV = {
|
||||
@@ -160,6 +173,27 @@ def cleanup(project: str, containers: list[str]) -> bool:
|
||||
)
|
||||
|
||||
|
||||
def postgres_log_check(project: str) -> int:
|
||||
"""Журнал PostgreSQL стенда отказов: сводка всегда, признаки аварии —
|
||||
строками; 1 — признаки есть. Два счётчика
|
||||
FATAL показывают, что заполнение и освобождение слотов правда были."""
|
||||
log = dc(project, "logs", "--no-log-prefix", "postgres", quiet=True)
|
||||
lines = (log.stdout + log.stderr).splitlines()
|
||||
crashes = [line for line in lines if any(m in line for m in CRASH_MARKERS)]
|
||||
too_many = sum("too many clients" in line for line in lines)
|
||||
admin = sum("administrator command" in line for line in lines)
|
||||
say(
|
||||
f"postgres log: {len(lines)} lines, crash markers {len(crashes)}; "
|
||||
f'"too many clients" {too_many}, "administrator command" {admin}',
|
||||
)
|
||||
if not crashes:
|
||||
return 0
|
||||
say("crash markers in the postgres log:")
|
||||
for line in crashes[:CRASH_LINES_MAX]:
|
||||
print(line, flush=True)
|
||||
return 1
|
||||
|
||||
|
||||
def start_api(
|
||||
project: str,
|
||||
name: str,
|
||||
@@ -234,6 +268,8 @@ def main() -> int:
|
||||
env=env,
|
||||
).returncode
|
||||
failed = bool(results["fault"])
|
||||
# стенд ещё жив: журнал PostgreSQL до уборки
|
||||
results["postgres"] = postgres_log_check(project)
|
||||
except KeyboardInterrupt:
|
||||
say("interrupted")
|
||||
results["interrupted"] = 130
|
||||
|
||||
Reference in New Issue
Block a user