"""KIS 스트림 무수신 경보: 등록 0건(대시보드 미접속)은 정상 — 2026-10-12 운영 오경보 3건.""" import app.main as m class _T: def __init__(self, done): self._d = done def done(self): return self._d class _App: class state: pass def _app(done=False): a = _App() a.state = type("S", (), {})() a.state.kis_stream_task = _T(done) return a def test_zero_registrations_is_not_silent(monkeypatch): monkeypatch.setattr(m, "_kis_stream_last_msg_mono", 100.0) monkeypatch.setattr(m, "_kis_stream_regs_since", None) limit = m._HB_KIS_STREAM_SILENT_SECONDS r = m._kis_stream_health_v3(_app(), now=100.0 + limit + 1, market_open=True, registrations=0) assert r["silent"] is False and r["registrations"] == 0 def test_dead_task_is_silent_even_with_zero_registrations(monkeypatch): monkeypatch.setattr(m, "_kis_stream_last_msg_mono", 100.0) monkeypatch.setattr(m, "_kis_stream_regs_since", None) r = m._kis_stream_health_v3(_app(done=True), now=101.0, market_open=True, registrations=0) assert r["silent"] is True def test_resubscribe_uses_registration_time_as_reference(monkeypatch): limit = m._HB_KIS_STREAM_SILENT_SECONDS monkeypatch.setattr(m, "_kis_stream_last_msg_mono", 100.0) monkeypatch.setattr(m, "_kis_stream_regs_since", None) t0 = 100.0 + limit + 500 # 옛 메시지 이후 오래 지나 재구독 assert m._kis_stream_health_v3(_app(), now=t0, market_open=True, registrations=8)["silent"] is False assert m._kis_stream_health_v3(_app(), now=t0 + limit - 1, market_open=True, registrations=8)["silent"] is False assert m._kis_stream_health_v3(_app(), now=t0 + limit + 1, market_open=True, registrations=8)["silent"] is True def test_registered_and_receiving_is_not_silent(monkeypatch): limit = m._HB_KIS_STREAM_SILENT_SECONDS monkeypatch.setattr(m, "_kis_stream_regs_since", 0.0) monkeypatch.setattr(m, "_kis_stream_last_msg_mono", 1000.0) assert m._kis_stream_health_v3(_app(), now=1000.0 + limit - 5, market_open=True, registrations=8)["silent"] is False def test_unknown_registrations_falls_back_to_v2(monkeypatch): limit = m._HB_KIS_STREAM_SILENT_SECONDS monkeypatch.setattr(m, "_kis_stream_last_msg_mono", 100.0) monkeypatch.setattr(m, "_kis_stream_regs_since", None) assert m._kis_stream_health_v3(_app(), now=100.0 + limit + 1, market_open=True, registrations=None)["silent"] is True