Supertester.TestableGenServer (Supertester v0.6.0)

Copy Markdown View Source

A behavior that makes GenServers testable with Supertester.

This module injects a __supertester_sync__ handler that allows tests to synchronize with the GenServer without using Process.sleep/1.

Usage

defmodule MyServer do
  use GenServer
  use Supertester.TestableGenServer

  # Your GenServer implementation
end

Synchronization

The injected handler responds to two message formats:

  • :__supertester_sync__ - Returns :ok after processing
  • {:__supertester_sync__, return_state: true} - Returns {:ok, state}

Example

{:ok, server} = MyServer.start_link()
GenServer.cast(server, :some_operation)

# Ensure cast is processed before continuing
GenServer.call(server, :__supertester_sync__)

# Now safe to verify results
state = :sys.get_state(server)