Mailglass.Adapters.Fake.Storage (Mailglass v0.1.0)

Copy Markdown View Source

GenServer owning the :mailglass_fake_mailbox ETS table. Mirrors Swoosh.Adapters.Sandbox.Storage pattern: the GenServer handles ownership mutations (checkout, checkin, allow, set_shared, find_owner, {:DOWN, ...}) but READS happen directly against ETS to bypass the mailbox.

State

  • :owners — MapSet of currently-checked-out owner pids.
  • :allowed — map allowed_pid => owner_pid for allow-list delegation (LiveView, Playwright, Oban worker processes).
  • :shared — single owner pid for global-mode tests (set via set_shared/1).
  • :monitors — map monitor_ref => pid for auto-cleanup on DOWN.

ETS table

:mailglass_fake_mailbox[:set, :named_table, :public, {:read_concurrency, true}]. Keys: owner pid. Values: list of records (prepended on each push, so newest is head).

Divergences from Swoosh.Adapters.Sandbox.Storage

  1. Table name: :mailglass_fake_mailbox (not :swoosh_sandbox_emails).
  2. Stored value: %{message: %Mailglass.Message{}, delivery_id: binary(), provider_message_id: binary(), recorded_at: DateTime.t()} — not a bare email.
  3. send(owner_pid, {:mail, msg}) — not {:email, email}.
  4. push/2 accepts owner_pid + record_map; stores full record in ETS.

Summary

Functions

Returns all records for the given owner pid. Newest first.

Returns a specification to start this module under a supervisor.

Removes the ETS entry for the given owner pid.

Removes all entries from the ETS table (used by Fake.clear(:all)).

Functions

all(owner_pid)

Returns all records for the given owner pid. Newest first.

allow(owner_pid, allowed_pid)

checkin()

checkout()

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

clear(owner_pid)

Removes the ETS entry for the given owner pid.

find_owner(callers)

flush()

Removes all entries from the ETS table (used by Fake.clear(:all)).

get_shared()

push(owner_pid, record)

set_shared(pid)

start_link(opts \\ [])