View Source EchoPubSub.FaultInjection (EchoPubSub v0.2.3)
Single source of truth for the compile-time fault-injection switch, shared by the producer (outgoing) and worker (incoming) to simulate a network partition.
In production builds ok?/0 is a hardcoded true that no runtime setting can
flip, so injected faults can never activate. The switch is enabled under
:test, or when a consuming app opts in for a demo:
# config/config.exs
config :echo_pubsub, :enable_fault_injection, trueOnce enabled, ok?/0 honors the runtime :fault_injection flag, toggled with
Application.put_env(:echo_pubsub, :fault_injection, :error | :ok).
Summary
Functions
Runs the do block, or the else block while a fault is injected.
Whether to deliver normally (true) or inject a fault (false).
Functions
Runs the do block, or the else block while a fault is injected.
When fault injection is off, only the do block is compiled, so production code
has no fault branch at all.
FaultInjection.if_ok do
deliver()
else
:error
end
@spec ok?() :: boolean()
Whether to deliver normally (true) or inject a fault (false).