An owner-scoped backend that records checkpoints per test, with
NimbleOwnership.
Configure it in the test environment and start its ownership server from
test_helper.exs:
# config/test.exs
config :dd_data_streams, backend: DdDataStreams.Testing.Backend
# test/test_helper.exs
{:ok, _} = DdDataStreams.Testing.Backend.start_link()A process records only when it owns the checkpoints or was allowed to use
them, so a test that never opts in sees the library exactly as if it were
disabled. DdDataStreams.Testing is the public interface; this module is
the seam it installs.
The ownership server is private by default, which is what makes concurrent
tests independent. DdDataStreams.Testing.set_global/1 switches it to the
shared, single-owner mode for an async: false case. Production code never
starts this server and never depends on it running: without it enabled?/0
is false and record/1 drops the checkpoint.
Summary
Functions
Allows allowed to record into owner.
The checkpoints recorded for owner, oldest first.
A child specification for starting the ownership server in a supervision
tree, instead of from test_helper.exs.
Picks private mode for an async case and shared mode otherwise.
Switches the ownership server to shared mode, with the calling process as the owner every caller records into.
Switches the ownership server to private mode, the default.
Makes owner an owner of the checkpoints, so its own calls and its
$callers record into it.
Starts the ownership server under this module's name.
Subscribes the calling owner to {DdDataStreams.Testing, :checkpoint, point}
messages, in addition to the pull API in checkpoints/1.
Functions
@spec allow(pid() | atom(), pid() | atom()) :: :ok | {:error, NimbleOwnership.Error.t()}
Allows allowed to record into owner.
The checkpoints recorded for owner, oldest first.
@spec child_spec(keyword()) :: Supervisor.child_spec()
A child specification for starting the ownership server in a supervision
tree, instead of from test_helper.exs.
@spec set_from_context(map()) :: :ok
Picks private mode for an async case and shared mode otherwise.
@spec set_global(map()) :: :ok
Switches the ownership server to shared mode, with the calling process as the owner every caller records into.
@spec set_private(map()) :: :ok
Switches the ownership server to private mode, the default.
Makes owner an owner of the checkpoints, so its own calls and its
$callers record into it.
@spec start_link(keyword()) :: GenServer.on_start()
Starts the ownership server under this module's name.
Accepts the options NimbleOwnership.start_link/1 accepts. Calling it when
the server already runs returns {:error, {:already_started, pid}}, as any
named process does; a test helper usually starts it once.
@spec subscribe() :: :ok
Subscribes the calling owner to {DdDataStreams.Testing, :checkpoint, point}
messages, in addition to the pull API in checkpoints/1.