import logging from app.core import log_throttle as lt def test_throttle_once_per_interval_and_suppressed_count(caplog, monkeypatch): lt.reset_for_tests() t = [1000.0] monkeypatch.setattr(lt.time, "monotonic", lambda: t[0]) lg = logging.getLogger("t.throttle") with caplog.at_level(logging.WARNING, logger="t.throttle"): assert lt.warn_throttled(lg, "k", "boom %s", 1, interval=60) is True assert lt.warn_throttled(lg, "k", "boom %s", 2, interval=60) is False assert lt.warn_throttled(lg, "other", "x", interval=60) is True t[0] += 61 assert lt.warn_throttled(lg, "k", "boom %s", 3, interval=60) is True msgs = [r.getMessage() for r in caplog.records] assert msgs[0] == "boom 1" and "+1건 억제" in msgs[-1] assert all(r.levelno == logging.WARNING for r in caplog.records)