Skip to content

Commit 8211f2d

Browse files
committed
Add tests for _BaseCore: metric hooks default values and timeout behavior
1 parent a30fb90 commit 8211f2d

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

tests/test_base_core.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import pytest
77

8-
from cachier.cores.base import _BaseCore
8+
from cachier.cores.base import RecalculationNeeded, _BaseCore
99

1010

1111
class ConcreteCachingCore(_BaseCore):
@@ -143,3 +143,26 @@ async def test_base_core_aset_entry_fallback():
143143

144144
assert result is True
145145
assert core.last_set == (key, 99)
146+
147+
148+
def test_base_core_size_hooks_default_to_zero():
149+
"""Base metric hooks should return zero when a backend does not override them."""
150+
core = ConcreteCachingCore(hash_func=None, wait_for_calc_timeout=None)
151+
152+
assert core._get_entry_count() == 0
153+
assert core._get_total_size() == 0
154+
155+
156+
def test_check_calc_timeout_raises_recalculation_needed():
157+
"""check_calc_timeout should raise when elapsed time reaches the configured timeout."""
158+
core = ConcreteCachingCore(hash_func=None, wait_for_calc_timeout=2)
159+
160+
with pytest.raises(RecalculationNeeded):
161+
core.check_calc_timeout(2)
162+
163+
164+
def test_check_calc_timeout_does_not_raise_before_timeout():
165+
"""check_calc_timeout should not raise before the configured timeout."""
166+
core = ConcreteCachingCore(hash_func=None, wait_for_calc_timeout=2)
167+
168+
core.check_calc_timeout(1)

0 commit comments

Comments
 (0)