Unit tests for CODITECT Circuit Breaker
Tests cover:
- CircuitBreaker state machine (CLOSED → OPEN → HALF_OPEN → CLOSED)
- Failure counting and threshold transitions
- Recovery timeout behavior
- CircuitBreakerRegistry multi-breaker management
- AgentCircuitBreaker with fallback routing
- Decorator functionality
- Metrics collection
- Health check integration
- Edge cases and error handling
Part of Track H.2.4: Circuit Breaker Pattern Implementation Author: CODITECT Framework Created: January 8, 2026
File: test_circuit_breaker.py
Classes
TestCircuitBreakerConfig
Tests for CircuitBreakerConfig.
TestCircuitBreakerStateMachine
Tests for circuit breaker state transitions.
TestCircuitBreakerCalls
Tests for circuit breaker call handling.
TestExceptionFiltering
Tests for exception inclusion/exclusion.
TestCircuitBreakerControl
Tests for manual circuit control.
TestCircuitBreakerMetrics
Tests for metrics collection.
TestCircuitBreakerRegistry
Tests for the circuit breaker registry.
TestAgentCircuitBreaker
Tests for agent-specific circuit breaker.
TestDecorator
Tests for the circuit_breaker decorator.
TestHealthCheck
Tests for health check integration.
Functions
config()
Create a test configuration with fast timeouts.
breaker(config)
Create a circuit breaker with test config.
registry(config)
Create a registry with test config.
test_default_config()
Test default configuration values.
test_custom_config()
Test custom configuration values.
test_config_validation_fail_max()
Test that fail_max must be at least 1.
test_config_validation_recovery_timeout()
Test that recovery_timeout must be non-negative.
test_config_validation_half_open_max_calls()
Test that half_open_max_calls must be at least 1.
test_config_from_env()
Test configuration from environment variables.
test_initial_state_is_closed(breaker)
Test that circuit starts in CLOSED state.
test_sync_call(breaker)
Test synchronous call handling.
test_sync_call_exception(breaker, config)
Test synchronous call exception handling.
test_force_open(breaker)
Test forcing circuit open.
test_force_close(breaker, config)
Test forcing circuit closed.
test_reset(breaker)
Test resetting circuit breaker.
Usage
python test_circuit_breaker.py