Modeling the Circuit Breaker: The Property
Explore how to model and test a circuit breaker using state machine properties in Erlang. Understand the role of generators, state transitions, and preconditions in defining a property-based test model that captures realistic system behavior.
We'll cover the following...
We'll cover the following...
The property
Let’s start by looking at the property.
There will be four generators:
ok/1tripped/1blocked/1,unregistered/1
- This generator is added because manual calls aren’t available until the circuit breaker’s service id is registered, and this occurs automatically on first use. This peculiarity will be encoded in the state machine itself.
Here we’ll begin the circuit breaker process by hand, which is paired with a call to gen_server:stop/3 at line 6. The circuit breaker module doesn’t expose a callback to terminate the breaker, usually preferring to let a supervision tree do that work. The gen_server behavior, however, exposes functions that let us ...