From 0e7fd5059e8a813ccffe2c376b1ff43898b4d966 Mon Sep 17 00:00:00 2001 From: TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> Date: Thu, 2 Apr 2026 15:31:09 +0900 Subject: fix: address code review issues in resilience module --- shared/tests/test_resilience.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'shared/tests') 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 --- -- cgit v1.2.3