Octoroom.Agent.Pipeline.Test (octoroom_agents v0.1.0)

Copy Markdown View Source

Runs a pipeline spec in the calling process, with no sockets or timers, for tests.

import Octoroom.Agent.Pipeline.Spec
alias Octoroom.Agent.Pipeline.Test

harness =
  processor(MyApp.IgnoreBackchannel)
  |> Test.start!()
  |> Test.push([%Frames.VADUserStartedSpeaking{}, %Frames.InterimTranscription{text: "uh-huh"}])

refute Test.interrupted?(harness)

Async work runs according to :async:

  • :inline (default) - each task runs to completion in the calling process as soon as the frame that started it is handled. Its emitted messages are delivered in order, then its result.
  • :manual - tasks wait until run_tasks/1 or run_task/3, so a test can interrupt while work is in flight.

Timers never fire by themselves; use fire_timer/3.

Summary

Functions

{reason, fatal?} for each error that left the first stage, oldest first.

Fires the pending timer key of stage name.

Delivers a handle_info/2 message to stage name.

True if anything interrupted the pipeline.

Events sent with {:notify, event}, oldest first.

Frames that left the last stage, oldest first, optionally only of module.

Keys of the tasks waiting to run (:manual mode), as {stage_name, key}.

Pushes a frame (or a list of frames) into the pipeline.

True if a frame of module left the last stage.

Starts a harness and pushes frames downstream. Takes start/2's options.

Runs the waiting task key of stage name.

Runs every waiting task, including ones started by those tasks' results.

Starts a harness for spec. Options: :async (:inline or :manual), :ctx.

Like start/2, but raises on error.

The state of stage name.

True if stage name has a pending timer key.

Frames (other than errors) that left the first stage upstream, oldest first.

Types

t()

@type t() :: %Octoroom.Agent.Pipeline.Test{
  async: term(),
  core: term(),
  errors: term(),
  interruptions: term(),
  notifications: term(),
  observed: term(),
  outputs: term(),
  tasks: term(),
  timers: term(),
  upstream: term()
}

Functions

errors(test)

{reason, fatal?} for each error that left the first stage, oldest first.

fire_timer(harness, name, key)

Fires the pending timer key of stage name.

info(harness, name, message)

Delivers a handle_info/2 message to stage name.

interrupted?(test)

True if anything interrupted the pipeline.

notifications(test)

Events sent with {:notify, event}, oldest first.

outputs(test, module \\ nil)

Frames that left the last stage, oldest first, optionally only of module.

pending_tasks(harness)

Keys of the tasks waiting to run (:manual mode), as {stage_name, key}.

push(harness, frames, direction \\ :downstream)

Pushes a frame (or a list of frames) into the pipeline.

received?(harness, module)

True if a frame of module left the last stage.

run(spec, frames, opts \\ [])

Starts a harness and pushes frames downstream. Takes start/2's options.

run_task(harness, name, key)

Runs the waiting task key of stage name.

run_tasks(harness)

Runs every waiting task, including ones started by those tasks' results.

start(spec, opts \\ [])

Starts a harness for spec. Options: :async (:inline or :manual), :ctx.

start!(spec, opts \\ [])

Like start/2, but raises on error.

state(test, name)

The state of stage name.

timer_pending?(harness, name, key)

True if stage name has a pending timer key.

upstream(test)

Frames (other than errors) that left the first stage upstream, oldest first.