CouncilEx.Test (CouncilEx v0.1.0)

Copy Markdown View Source

Helpers for testing councils. Add import CouncilEx.Test in your test files.

Three helpers ship in v0.2:

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

assert_round_completed(round_name, run_id, timeout \\ 1000)

(macro)

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)).

capture_events(run_id, timeout \\ 5000)

@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.

script_council(council, scripts)

@spec script_council(module(), String.t() | map() | (atom(), module() -> String.t())) ::
  :ok

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.