diff options
Diffstat (limited to 'shared/tests/test_resilience.py')
| -rw-r--r-- | shared/tests/test_resilience.py | 23 |
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 --- |
