Helpers for testing councils. Add import CouncilEx.Test in your test files.
Three helpers ship in v0.2:
script_council/2— register Mock-provider scripts for every member of a council in one call.capture_events/2— drain PubSub events for a run until terminal event or timeout, return the ordered list.assert_round_completed/3— ExUnit assertion macro for:round_completed.
script_council/2 assumes members are routed to CouncilEx.Providers.Mock.
Mixed real/Mock councils are supported but only the Mock-routed members
receive the script — others ignore it.
Summary
Functions
Block until {:round_completed, run_id, round_name, %RoundResult{}} arrives,
or fail with caller file/line via ExUnit assertion. Returns the matched
%CouncilEx.RoundResult{} for further assertions.
Subscribe to the run topic, drain events until {:run_completed, _, _} /
{:run_failed, _, _, _} / timeout. Returns the ordered list including
terminal event.
Register a Mock script for every member of council.
Functions
Block until {:round_completed, run_id, round_name, %RoundResult{}} arrives,
or fail with caller file/line via ExUnit assertion. Returns the matched
%CouncilEx.RoundResult{} for further assertions.
The caller must be subscribed to the run's topic before calling this macro
(typically via CouncilEx.PubSub.subscribe("council_ex:run:" <> run_id)).
@spec capture_events(binary(), pos_integer()) :: [tuple()]
Subscribe to the run topic, drain events until {:run_completed, _, _} /
{:run_failed, _, _, _} / timeout. Returns the ordered list including
terminal event.
Note: subscription happens inside this call, so events emitted before
capture_events/2 returns (e.g., :run_started if the run has already
started) are lost. To capture every event, subscribe directly via
CouncilEx.PubSub.subscribe/1 before kicking off the run.
Register a Mock script for every member of council.
Three shapes for scripts:
- a string — every member receives
Mock.script(id, content: string). - a map of
member_id => string— per-member content. - a 2-arity fn
fn member_id, member_module -> content_string end— called once per member.