...

/

Modeling the Circuit Breaker: The Test Module

Modeling the Circuit Breaker: The Test Module

Complete the test module with the stateful generators and take a look at the completed test suite.

The preconditions

Let’s start off by taking a look at the preconditions.

### Picks whether a command should be valid
def precondition(:unregistered, :ok, _, {:call, _, call, _}) do
  call == :success
end
def precondition(:ok, to, %{errors: n, limit: l}, {:call, _, :err, _}) do
  (to == :tripped and n + 1 == l) or (to == :ok and n + 1 != l)
end
def precondition(
      :ok,
      to,
      %{timeouts: n, limit: l},
      {:call, _, :timeout, _}
    ) do
  (to == :tripped and n + 1 == l) or (to == :ok and n + 1 != l)
end
def precondition(_from, _to, _data, _call) do
  true
end

Notice how both calls to erroneous cases are only valid in mutually exclusive instances:

  • (to ==
...