Supertester.ETSIsolation (Supertester v0.6.0)

Copy Markdown View Source

Per-test ETS table management for async-safe isolation.

Summary

Functions

Create an isolated ETS table with automatic cleanup.

Get the mirror table for a source table.

Get the mirror table or raise if not found.

Temporarily replace a module's table reference.

Create an isolated copy of an existing named table.

Initialize ETS isolation for the current process.

Initialize ETS isolation and optionally auto-mirror tables or update context.

Initialize ETS isolation, auto-mirror tables, and update context.

Execute a function with a temporary ETS table that is deleted after scope.

Types

create_opt()

@type create_opt() ::
  {:name, atom()}
  | {:copy_from, table_ref()}
  | {:owner, pid()}
  | {:cleanup, boolean()}

create_opts()

@type create_opts() :: [table_option() | create_opt()]

inject_opt()

@type inject_opt() ::
  {:create, boolean()} | {:table_opts, [table_option()]} | {:cleanup, boolean()}

inject_opts()

@type inject_opts() :: [inject_opt()]

mirror_opt()

@type mirror_opt() ::
  {:include_data, boolean()} | {:access, table_access()} | {:cleanup, boolean()}

mirror_opts()

@type mirror_opts() :: [mirror_opt()]

table_access()

@type table_access() :: :public | :protected | :private

table_name()

@type table_name() :: atom()

table_option()

@type table_option() ::
  table_type()
  | table_access()
  | :named_table
  | {:keypos, pos_integer()}
  | {:heir, pid(), term()}
  | {:write_concurrency, boolean()}
  | {:read_concurrency, boolean()}
  | :compressed

table_ref()

@type table_ref() :: :ets.tid() | atom()

table_type()

@type table_type() :: :set | :ordered_set | :bag | :duplicate_bag

Functions

create_isolated(type, opts \\ [])

@spec create_isolated(table_type(), create_opts()) :: {:ok, table_ref()}

Create an isolated ETS table with automatic cleanup.

get_mirror(source_name)

@spec get_mirror(table_name()) :: {:ok, table_ref()} | {:error, :not_mirrored}

Get the mirror table for a source table.

get_mirror!(source_name)

@spec get_mirror!(table_name()) :: table_ref()

Get the mirror table or raise if not found.

inject_table(module, function_or_attribute, replacement, opts \\ [])

@spec inject_table(module(), atom(), table_name() | table_ref(), inject_opts()) ::
  {:ok, (-> :ok)}

Temporarily replace a module's table reference.

mirror_table(source_name, opts \\ [])

@spec mirror_table(table_name(), mirror_opts()) ::
  {:ok, table_ref()} | {:error, {:table_not_found, table_name()}}

Create an isolated copy of an existing named table.

setup_ets_isolation()

@spec setup_ets_isolation() :: :ok

Initialize ETS isolation for the current process.

setup_ets_isolation(tables)

@spec setup_ets_isolation([table_name()]) :: :ok
@spec setup_ets_isolation(Supertester.IsolationContext.t()) ::
  {:ok, Supertester.IsolationContext.t()}

Initialize ETS isolation and optionally auto-mirror tables or update context.

setup_ets_isolation(ctx, tables)

@spec setup_ets_isolation(Supertester.IsolationContext.t(), [table_name()]) ::
  {:ok, Supertester.IsolationContext.t()}

Initialize ETS isolation, auto-mirror tables, and update context.

with_table(type, fun)

@spec with_table(table_type(), (table_ref() -> term())) :: term()

Execute a function with a temporary ETS table that is deleted after scope.

with_table(type, opts, fun)

@spec with_table(table_type(), create_opts(), (table_ref() -> term())) :: term()