Files
new_lottery_bot/tests/test_health.py
Trevor1985 d5a9c13b68
All checks were successful
continuous-integration/drone/push Build is passing
Recover stalled database connections and skip unreachable chat recipients
2026-09-13 20:21:20 +09:00

32 lines
1.2 KiB
Python

import os
from pathlib import Path
import subprocess
import sys
def test_watchdog_exits_a_process_with_stalled_event_loop(tmp_path):
# A blocked event loop cannot run coroutine-based timeout handlers.
code = """import time
from src.core.health import start_watchdog
start_watchdog(grace_seconds=0.1, interval=0.02)
time.sleep(10)
"""
result = subprocess.run([sys.executable, "-c", code], cwd=Path(__file__).resolve().parents[1],
env=dict(os.environ, HEARTBEAT_FILE=str(tmp_path / "absent")),
capture_output=True, timeout=8)
assert result.returncode == 1
assert b"Heartbeat expired" in result.stderr
def test_stopped_watchdog_allows_normal_shutdown(tmp_path):
code = """import time
from src.core.health import start_watchdog
stopped = start_watchdog(grace_seconds=0.1, interval=0.02)
stopped.set()
time.sleep(0.2)
"""
result = subprocess.run([sys.executable, "-c", code], cwd=Path(__file__).resolve().parents[1],
env=dict(os.environ, HEARTBEAT_FILE=str(tmp_path / "absent")),
capture_output=True, timeout=8)
assert result.returncode == 0