ExMoQ.Test.Relay (ExMoQ v0.1.0)

Copy Markdown View Source

Runs a MoQ relay for ExUnit integration tests.

start_supervised!/1 starts a relay under the current test supervisor and blocks until it accepts connections:

relay = ExMoQ.Test.Relay.start_supervised!()
{:ok, session} = ExMoQ.Native.create_session(relay.url, self(), relay.disable_tls_verify?)

Call it in setup_all for a relay shared by the test module, or inside a single test when it needs its own instance.

The relay runs as a MuonTrap.Daemon, which guarantees the OS process is torn down with the supervisor. Muontrap is an optional dependency of :ex_moq, so the host project must depend on it directly: {:muontrap, "~> 1.8", only: :test}.

moq-relay must be available in the environment: For how the binary path gets resolved, see find_binary/1.

The relay listens on TCP for lossless transport, but groups can still be dropped as part of eviction policies.

Summary

Functions

Resolves the path of the moq-relay binary from the :binary option, the $MOQ_RELAY environment variable, or $PATH; returns nil if none of them yields an executable.

Starts a relay under the ExUnit test supervisor and blocks until it accepts connections.

Stops a relay started with start_supervised!/1, blocking until it is down.

Types

option()

@type option() :: {:binary, Path.t()}

t()

@type t() :: %ExMoQ.Test.Relay{
  disable_tls_verify?: boolean(),
  id: term(),
  url: String.t()
}

Functions

find_binary(opts \\ [])

@spec find_binary([option()]) :: Path.t() | nil

Resolves the path of the moq-relay binary from the :binary option, the $MOQ_RELAY environment variable, or $PATH; returns nil if none of them yields an executable.

start_supervised!(opts \\ [])

@spec start_supervised!([option()]) :: t()

Starts a relay under the ExUnit test supervisor and blocks until it accepts connections.

The relay can be stopped mid-test with stop_supervised!/1.

Raises if no moq-relay binary is found, or if the relay exits or does not accept connections within 15000 ms.

stop_supervised!(relay)

@spec stop_supervised!(t()) :: :ok

Stops a relay started with start_supervised!/1, blocking until it is down.