summaryrefslogtreecommitdiff
path: root/shared/tests/test_resilience.py
diff options
context:
space:
mode:
authorTheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com>2026-04-02 15:31:09 +0900
committerTheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com>2026-04-02 15:31:09 +0900
commit0e7fd5059e8a813ccffe2c376b1ff43898b4d966 (patch)
tree3a4da6bcf61637e1e94907048c7110d7d3daabee /shared/tests/test_resilience.py
parent24cb407ef15f1997e2577c58e139b20d3986ed5b (diff)
fix: address code review issues in resilience module
Diffstat (limited to 'shared/tests/test_resilience.py')
-rw-r--r--shared/tests/test_resilience.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/shared/tests/test_resilience.py b/shared/tests/test_resilience.py
index dde47e1..5ed4ac3 100644
--- a/shared/tests/test_resilience.py
+++ b/shared/tests/test_resilience.py
@@ -136,6 +136,29 @@ async def test_half_open_after_cooldown():
assert result == "recovered"
+async def test_half_open_reopens_on_failure():
+ cb = CircuitBreaker(failure_threshold=2, cooldown=0.05)
+
+ async def always_fail():
+ raise ConnectionError("fail")
+
+ # Trip the breaker
+ for _ in range(2):
+ with pytest.raises(ConnectionError):
+ await cb.call(always_fail)
+
+ # Wait for cooldown
+ await asyncio.sleep(0.1)
+
+ # Half-open probe should fail and re-open
+ with pytest.raises(ConnectionError):
+ await cb.call(always_fail)
+
+ # Should be open again (no cooldown wait)
+ with pytest.raises(RuntimeError, match="Circuit breaker is open"):
+ await cb.call(always_fail)
+
+
# --- async_timeout tests ---