View Source Testcontainers.Reaper (testcontainers v1.0.0)

A GenServer that manages the lifecycle of the Ryuk container within the Testcontainers ecosystem.

The Reaper is responsible for ensuring that resources are cleaned up properly when test containers are no longer needed. It communicates with the Ryuk container, a tool used by Testcontainers to reap orphaned containers.

Usage

The module is typically used in the context of integration tests where test containers are employed. It starts the Ryuk container and registers filters for cleaning up resources.

It is meant to be started before interacting with any test containers and stopped after all tests are concluded.

Note: This is an internal component and should not be used directly in tests. Instead, it's used by the higher-level Testcontainers APIs.

Summary

Functions

Returns a specification to start this module under a supervisor.

Registers a filter with the Ryuk container for resources to be reaped.

Starts the Reaper process if it is not already running.

Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

Registers a filter with the Ryuk container for resources to be reaped.

This function sends a message to the Reaper, which communicates with the Ryuk container to establish a filter based on the provided criteria. Resources that match the filter will be monitored and cleaned up by Ryuk once they are no longer needed.

Examples

iex> Testcontainers.Reaper.register({"label", "com.example.test-session"})
:ok

Parameters

  • filter: A tuple representing the filter key and value. Resources within the scope of Testcontainers that match this filter will be eligible for cleanup.

Note

The function is a cast operation; it does not return any value and will silently fail if there's an issue. It's designed to be fire-and-forget for setting up cleanup filters, to avoid tests failing if the reaper is not running.

Starts the Reaper process if it is not already running.

This function will start the Reaper unlinked (outside of the current supervision tree) and wait until it's registered with the local process registry.

It's particularly useful for scenarios where the Reaper needs to be started without a linked supervision strategy, often before the actual test scenarios are executed.

Examples

iex> Testcontainers.Reaper.start_eager()
{:ok, pid}

Options

The function accepts an optional list of options (opts) that are passed to the GenServer initialization, though in the current implementation, these options are not used.

Errors

If the Reaper fails to start, the function will return an error tuple.

Note

This function is designed to be used in setup scenarios, possibly within test suite setup callbacks.