Cucumber.RunCoordinator (Cucumber v1.0.0)

View Source

Run-wide coordination process for cucumber test runs.

Started (or reset) by Cucumber.compile_features!/1 — which runs from test_helper.exs before any test executes, so startup is race-free. State is keyed by a run id that changes on every compile_features! call, so repeated runs in one VM (mix test.watch, test harnesses) never see stale state.

Current run-scoped concerns:

  • BeforeAll once-guardbefore_all_context/1 runs the run's before_all hooks exactly once (serialized through the GenServer, so concurrent @async scenarios are safe) and caches the merged context (or the first error) for every subsequent scenario.
  • AfterAll hand-offregister_after_all/1 stores the run's after_all hooks; the ExUnit.after_suite/1 callback registered by the compiler claims them exactly once via run_after_all/1.
  • Attachmentsrecord_attachment/2 collects Cucumber.Attachment structs (see Cucumber.attach/4) in run order; attachments/0 returns them.
  • Cucumber Messages sink — when config :cucumber, messages: path is set, Cucumber.Messages.Emitter configures the sink with the run's static envelopes and id maps (configure_messages/1); the runner then appends run-time envelopes in order (emit_runtime/1, take_message_ids/1, finish_test_case/3), and the after_suite callback flushes the NDJSON file (flush_messages/1), reconciling test cases the runner never finished (e.g. a killed test process). Serializing emission through this process is what keeps the stream ordered under @async features. Note that ExUnit.after_suite/1 callbacks fire on every ExUnit.run/1 — the sink flushes (and disables itself) when the first run in the VM completes, so a project that invokes a nested ExUnit.run/1 mid-suite with the sink enabled gets the stream truncated at that point (Cucumber.BehaviorCase relies on exactly this per-run firing to capture streams in tests).

Summary

Functions

Returns a specification to start this module under a supervisor.

Starts the coordinator for a new run, or resets it if already running.

Returns the current run id.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

ensure_started()

@spec ensure_started() :: integer()

Starts the coordinator for a new run, or resets it if already running.

Returns the new run id.

run_id()

@spec run_id() :: integer()

Returns the current run id.