"""R6: 서킷브레이커 OPEN 경보 태스크 참조 보관.""" import asyncio import pytest from app.services import korea_investment_api as kia @pytest.mark.asyncio async def test_alert_task_held_and_released(monkeypatch): from app.services.telegram_notifier import telegram_notifier gate = asyncio.Event() async def fake(*a, **k): await gate.wait() monkeypatch.setattr(telegram_notifier, "notify_system_warning", fake) kia._breaker_alert_tasks.clear() cb = kia.CircuitBreaker(failure_threshold=1, recovery_timeout=1) kia._alert_breaker_open_v2(cb) assert len(kia._breaker_alert_tasks) == 1 gate.set() await asyncio.sleep(0.05) assert len(kia._breaker_alert_tasks) == 0 @pytest.mark.asyncio async def test_alert_task_exception_logged_not_raised(monkeypatch, caplog): from app.services.telegram_notifier import telegram_notifier async def boom(*a, **k): raise RuntimeError("tg down") monkeypatch.setattr(telegram_notifier, "notify_system_warning", boom) kia._breaker_alert_tasks.clear() cb = kia.CircuitBreaker(failure_threshold=1, recovery_timeout=1) kia._alert_breaker_open_v2(cb) await asyncio.sleep(0.05) assert not kia._breaker_alert_tasks assert "경보 태스크 실패" in caplog.text