Skip to content

Commit cdc518c

Browse files
devin-ai-integration[bot]bot_apk
andcommitted
fix(cdk): validate check_interval >= 1 to prevent ZeroDivisionError
Co-Authored-By: bot_apk <apk@cognition.ai>
1 parent c96825f commit cdc518c

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

airbyte_cdk/utils/memory_monitor.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ def __init__(
4343
critical_threshold: float = _DEFAULT_CRITICAL_THRESHOLD,
4444
check_interval: int = _DEFAULT_CHECK_INTERVAL,
4545
) -> None:
46+
if check_interval < 1:
47+
raise ValueError(f"check_interval must be >= 1, got {check_interval}")
4648
self._warning_threshold = warning_threshold
4749
self._critical_threshold = critical_threshold
4850
self._check_interval = check_interval

unit_tests/utils/test_memory_monitor.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,23 @@ def mock_read_text(self: Path) -> str:
4545
return mock_read_text
4646

4747

48+
# ---------------------------------------------------------------------------
49+
# __init__ — input validation
50+
# ---------------------------------------------------------------------------
51+
52+
53+
def test_check_interval_zero_raises() -> None:
54+
"""check_interval=0 should raise ValueError at construction time."""
55+
with pytest.raises(ValueError, match="check_interval must be >= 1"):
56+
MemoryMonitor(check_interval=0)
57+
58+
59+
def test_check_interval_negative_raises() -> None:
60+
"""Negative check_interval should raise ValueError at construction time."""
61+
with pytest.raises(ValueError, match="check_interval must be >= 1"):
62+
MemoryMonitor(check_interval=-1)
63+
64+
4865
# ---------------------------------------------------------------------------
4966
# check_memory_usage — no-op paths
5067
# ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)