1---2name: supertester-otp-testing3description: This skill should be used when teams need to adopt Supertester to build deterministic Elixir OTP tests with isolation, synchronization, and supervision coverage.4license: Complete terms in LICENSE5---6
7# Supertester OTP Testing
8
9## When To Trigger
10- Activate whenever writing or reviewing new OTP-heavy tests so Supertester foundations are considered before adding bespoke helpers.
11- Activate when eliminating flaky OTP tests, `Process.sleep/1` calls, or race conditions in Elixir suites.
12- Activate when installing or upgrading Supertester and clarifying how OTP helpers should shape new or existing tests.
13- Activate when validating supervision restarts, chaos scenarios, or performance contracts with Supertester-provided tooling.
14
15## Core Goals
16- Establish isolation with `Supertester.UnifiedTestFoundation` and run OTP tests safely with `async: true`.
17- Retrofit GenServers and supervisors to use deterministic synchronization via Supertester helpers.
18- Replace bespoke OTP utilities with the official helpers and assertions in `lib/supertester`.
19- Surface reusable diagnostics that make failures obvious and repeatable.
20
21## Quick Orientation
22- Review `README.md` for feature highlights and before/after examples.
23- Use `MANUAL.md` for full API coverage; jump to the “OTP Testing Helpers” section for signatures.
24- Keep `docs/QUICK_START.md` on hand for migration recipes and example code.
25- Inspect source modules directly (`lib/supertester/otp_helpers.ex`, `lib/supertester/genserver_helpers.ex`, `lib/supertester/unified_test_foundation.ex`, `lib/supertester/testable_genserver.ex`, `lib/supertester/assertions.ex`) whenever implementation details matter.
26
27## Setup Workflow
281. Add `{:supertester, "~> 0.2.1", only: :test}` to `mix.exs` and run `mix deps.get` to install.
292. Use `Supertester.UnifiedTestFoundation` in each OTP-heavy test module, defaulting to `isolation: :full_isolation` unless constraints require lighter modes.
303. Import helper namespaces explicitly:
31 ```elixir
32 import Supertester.OTPHelpers
33 import Supertester.GenServerHelpers
34 import Supertester.Assertions
35 ```
364. Mark eligible cases `async: true` (automatically supplied by the isolation macro) and rely on helper-driven cleanup instead of manual teardown.
37
38## GenServer Workflow
39- Start isolated servers via `setup_isolated_genserver/3`, passing custom `:init_args` or explicit names through opts.
40- Apply `use Supertester.TestableGenServer` inside target modules to expose the `__supertester_sync__` handler without redefining `handle_call/3`.
41- Replace bare casts with `cast_and_sync/3` followed by `assert_genserver_state/2` or `assert_genserver_responsive/1`.
42- Leverage `call_with_timeout/3`, `get_server_state_safely/1`, `monitor_process_lifecycle/1`, and `cleanup_on_exit/1` to observe asynchronous behavior deterministically.
43
44### Example Pattern
45```elixir
46defmodule MyApp.CounterTest do
47 use ExUnit.Case
48 use Supertester.UnifiedTestFoundation, isolation: :full_isolation
49
50 import Supertester.OTPHelpers
51 import Supertester.GenServerHelpers
52 import Supertester.Assertions
53
54 test "increments without race conditions" do
55 {:ok, counter} = setup_isolated_genserver(MyApp.Counter)
56
57 :ok = cast_and_sync(counter, :increment)
58 assert_genserver_state(counter, fn state -> state.count == 1 end)
59 end
60end
61```
62
63## Supervisor & Restart Testing
64- Start trees with `setup_isolated_supervisor/3` and confirm readiness through `wait_for_supervisor_restart/2` or `wait_for_supervisor_stabilization/2`.
65- Probe restart semantics using `test_restart_strategy/3`, then assert outcomes with helpers such as `assert_process_restarted/2` and `assert_all_children_alive/1`.
66- Trace living supervision events via `trace_supervision_events/2` to capture restarts without manual logging.
67- Enable `isolation: :contamination_detection` when diagnosing leaks; review warnings emitted by `Supertester.UnifiedTestFoundation`.
68
69## Chaos And Performance Hooks
70- Exercise resilience with `Supertester.ChaosHelpers`, following scenario setups in `README.md` and option references in `MANUAL.md`.
71- Guard service-level objectives using `Supertester.PerformanceHelpers`, pairing `assert_performance/2` or `assert_no_memory_leak/2` with isolated fixtures.
72
73## Assertions & Diagnostics
74- Favor OTP-aware checks from `lib/supertester/assertions.ex` (`assert_genserver_handles_message/3`, `assert_process_dead/1`, `assert_no_process_leaks/1`) instead of bespoke assertions.
75- Run `verify_test_isolation/1` when isolations feel suspect to confirm all tracked processes remain sandboxed.
76- Capture process exits intentionally with `wait_for_process_death/2` and translate restarts to deterministic expectations.
77
78## Reference Bundle
79- Load `MANUAL.md#otp-testing-helpers` for signature verification mid-task.
80- Consult `docs/API_GUIDE.md` for extended examples and edge-case notes.
81- Check `CHANGELOG.md` before depending on newer APIs or behavior changes.
82
83## Reuse Checklist
84- Confirm each GenServer under test `use Supertester.TestableGenServer`.
85- Ensure every asynchronous assertion flows through `cast_and_sync/3`, `wait_for_genserver_sync/2`, or equivalent helpers.
86- Replace any remaining `Process.sleep/1` usage with Supertester synchronization.
87- Remove redundant in-house OTP helpers once the Supertester equivalents are adopted.