diff --git a/services/circuit_breaker.py b/services/circuit_breaker.py index 0d05530..c80340e 100644 --- a/services/circuit_breaker.py +++ b/services/circuit_breaker.py @@ -17,7 +17,7 @@ class CircuitBreaker: - """Consecutive-failure breaker: closed -> open (after N fails) -> half-open (after cooldown).""" + """Consecutive-failure breaker: closed, opens after N fails, half-opens to probe after a cooldown.""" def __init__( self, @@ -55,9 +55,9 @@ def record_success(self) -> None: def record_failure(self) -> bool: """Count a failed call. - Returns True iff this failure *just* tripped the breaker open (callers - can use that edge to emit a one-shot notification). A failed half-open - probe restarts the cooldown but does not re-trip. + Returns True iff this failure *just* tripped the breaker into the open + state, so callers can emit a one-shot notification on that edge. A failed + half-open probe restarts the cooldown but does not re-trip. """ with self._lock: self._failures += 1 diff --git a/tests/test_circuit_breaker.py b/tests/test_circuit_breaker.py index 781dd66..14a6c7d 100644 --- a/tests/test_circuit_breaker.py +++ b/tests/test_circuit_breaker.py @@ -10,7 +10,7 @@ def test_closed_until_threshold_then_opens(): assert br.record_failure() is False # 1 assert br.record_failure() is False # 2 assert br.allow() # still closed below threshold - assert br.record_failure() is True # 3 -> trips open (edge) + assert br.record_failure() is True # 3 -> trips it open at threshold assert not br.allow() # open, within cooldown assert br.is_open