Brama.TestHelpers (Brama v1.0.1)

View Source

Provides helper functions for testing applications that use Brama.

This module is intended to be used in test environments to:

  • Manipulate circuit states directly
  • Simulate failures and recovery

Usage

# In your test file
use ExUnit.Case
import Brama.TestHelpers

test "circuit opens after failures" do
  # Setup
  Brama.register("test_api")

  # Simulate failures
  add_failures("test_api", 10)

  # Assert circuit state
  assert {:ok, %{state: :open}} = Brama.status("test_api")
end

Summary

Functions

Adds a specific number of failures to a connection.

Directly sets the state of a circuit.

Simulates a service temporarily failing.

Simulates a service recovering.

Functions

add_failures(identifier, count, opts \\ [])

@spec add_failures(String.t(), non_neg_integer(), Keyword.t()) ::
  :ok | {:error, term()}

Adds a specific number of failures to a connection.

Examples

iex> add_failures("payment_api", 5)
:ok

set_state(identifier, state, opts \\ [])

@spec set_state(String.t(), atom(), Keyword.t()) :: :ok | {:error, term()}

Directly sets the state of a circuit.

Examples

iex> set_state("payment_api", :open)
:ok

simulate_failures(identifier, count, opts \\ [])

@spec simulate_failures(String.t(), non_neg_integer(), Keyword.t()) ::
  :ok | {:error, term()}

Simulates a service temporarily failing.

Examples

iex> simulate_failures("payment_api", 5)
:ok

simulate_recovery(identifier, opts \\ [])

@spec simulate_recovery(String.t(), Keyword.t()) :: :ok | {:error, term()}

Simulates a service recovering.

Examples

iex> simulate_recovery("payment_api")
:ok