Supertester.UnifiedTestFoundation (Supertester v0.6.0)

Copy Markdown View Source

Isolation runtime for OTP-heavy tests.

This module configures and maintains isolation contexts that can be plugged into any test harness. Use Supertester.ExUnitFoundation for the ready-made ExUnit adapter, or call the functions in this module directly from custom harnesses.

Isolation Modes

  • :basic - Basic isolation with unique naming
  • :registry - Registry-based process isolation
  • :full_isolation - Complete process and ETS isolation
  • :contamination_detection - Isolation with contamination detection

Usage with ExUnit

defmodule MyApp.MyModuleTest do
  use Supertester.ExUnitFoundation, isolation: :full_isolation

  test "my test", context do
    # Test runs with full isolation
  end
end

Usage with custom harnesses

:ok = Supertester.UnifiedTestFoundation.setup_isolation(:full_isolation, context)

Summary

Functions

Deprecated macro maintained for backwards compatibility.

Adds a cleanup callback to the isolation context.

Adds a tracked ETS table to the isolation context.

Adds a tracked process to the isolation context.

Fetches the isolation context stored in the current process.

Returns whether the isolation type allows async testing.

Returns the timeout for the isolation type.

Stores the isolation context in the current process.

Sets up test isolation based on the specified isolation type.

Verifies test isolation has been maintained.

Waits for a supervision tree to be ready.

Functions

__using__(opts)

(macro)

Deprecated macro maintained for backwards compatibility.

add_cleanup_callback(ctx, callback)

@spec add_cleanup_callback(Supertester.IsolationContext.t(), (-> any())) ::
  Supertester.IsolationContext.t()

Adds a cleanup callback to the isolation context.

add_tracked_ets_table(ctx, table)

@spec add_tracked_ets_table(Supertester.IsolationContext.t(), term()) ::
  Supertester.IsolationContext.t()

Adds a tracked ETS table to the isolation context.

add_tracked_process(ctx, process_info)

Adds a tracked process to the isolation context.

fetch_isolation_context()

@spec fetch_isolation_context() :: Supertester.IsolationContext.t() | nil

Fetches the isolation context stored in the current process.

isolation_allows_async?(atom)

@spec isolation_allows_async?(atom()) :: boolean()

Returns whether the isolation type allows async testing.

isolation_timeout(atom)

@spec isolation_timeout(atom()) :: non_neg_integer()

Returns the timeout for the isolation type.

put_isolation_context(context)

@spec put_isolation_context(Supertester.IsolationContext.t() | nil) ::
  Supertester.IsolationContext.t() | nil

Stores the isolation context in the current process.

setup_isolation(isolation_type, context)

@spec setup_isolation(atom(), map()) :: {:ok, map()}

Sets up test isolation based on the specified isolation type.

verify_test_isolation(context)

@spec verify_test_isolation(map()) :: boolean()

Verifies test isolation has been maintained.

wait_for_supervision_tree_ready(supervisor_pid, timeout \\ 5000)

@spec wait_for_supervision_tree_ready(pid(), non_neg_integer()) ::
  {:ok, pid()} | {:error, :timeout}

Waits for a supervision tree to be ready.