Files
mtusi2026lab2/student-tests/pool_settings.py
T
Чиняева df31f4a9fb Реализовать лабораторную 2 на оценку 4
PostgreSQL как источник истины, непрозрачные сессии в Redis с TTL и AOF, миграции под advisory lock, пул и таймауты, проверки гонки/отката/отказов и отчёт с evidence.
2026-11-06 22:37:31 +03:00

39 lines
1.2 KiB
Python

#!/usr/bin/env python3
"""Print the effective PostgreSQL timeouts and pool limits.
Run inside the API container:
docker compose exec -T api python student-tests/pool_settings.py
"""
from __future__ import annotations
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
from app import db
def main() -> None:
db.pool().open(wait=True, timeout=5)
db.apply_migrations()
with db.pool().connection() as conn:
statement = conn.execute("SHOW statement_timeout").fetchone()["statement_timeout"]
idle = conn.execute("SHOW idle_in_transaction_session_timeout").fetchone()[
"idle_in_transaction_session_timeout"
]
lock = conn.execute("SHOW lock_timeout").fetchone()["lock_timeout"]
stats = db.pool().get_stats()
print("statement_timeout =", statement)
print("idle_in_transaction_session_timeout =", idle)
print("lock_timeout =", lock)
print("pool_min =", stats["pool_min"])
print("pool_max =", stats["pool_max"])
print("pool_size =", stats["pool_size"])
print("pool_available =", stats["pool_available"])
print("PASS: bounded pool and SQL timeouts are active")
if __name__ == "__main__":
main()