# `DdDataStreams.Testing.Backend`
[🔗](https://github.com/rockneurotiko/dd_data_streams/blob/main/lib/dd_data_streams/testing/backend.ex#L2)

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.

# `allow`

```elixir
@spec allow(pid() | atom(), pid() | atom()) ::
  :ok | {:error, NimbleOwnership.Error.t()}
```

Allows `allowed` to record into `owner`.

# `checkpoints`

```elixir
@spec checkpoints(pid() | atom()) :: [map()]
```

The checkpoints recorded for `owner`, oldest first.

# `child_spec`

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

# `set_from_context`

```elixir
@spec set_from_context(map()) :: :ok
```

Picks private mode for an async case and shared mode otherwise.

# `set_global`

```elixir
@spec set_global(map()) :: :ok
```

Switches the ownership server to shared mode, with the calling process as
the owner every caller records into.

# `set_private`

```elixir
@spec set_private(map()) :: :ok
```

Switches the ownership server to private mode, the default.

# `start`

```elixir
@spec start(pid() | atom()) :: :ok
```

Makes `owner` an owner of the checkpoints, so its own calls and its
`$callers` record into it.

# `start_link`

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

# `subscribe`

```elixir
@spec subscribe() :: :ok
```

Subscribes the calling owner to `{DdDataStreams.Testing, :checkpoint, point}`
messages, in addition to the pull API in `checkpoints/1`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
