View Source Polyn.Sandbox (Polyn v0.6.5)

Sandbox environment for mocking NATS and keeping tests isolated

Add the following to your test_helper.ex

Polyn.Sandbox.start_link()

nested-processes

Nested Processes

Polyn.Testing associates each test process with its own NATS mock. To allow other processes that will call Polyn functions to use the same NATS mock as the rest of the test use the Polyn.Sandbox.allow/2 function. If you don't have access to the pid or name of a process that is using Polyn you will need to make your file async: false.

Link to this section Summary

Functions

Allow a child process, that is not the test process, to access the running MockNats server. You cannot allow the same process on multiple tests.

Returns a specification to start this module under a supervisor.

Get the nats server for a given pid

Get the async mode of the Sandbox. Defaults to false

Make the sandbox async false or true

Setup a test with a mock nats server association

Start the Sandbox

Get the full state

Remove the nats server assocation when a test is finished

Link to this section Functions

Link to this function

allow(test_pid, other_pid)

View Source
@spec allow(test_pid :: pid(), other_pid :: pid()) :: :ok

Allow a child process, that is not the test process, to access the running MockNats server. You cannot allow the same process on multiple tests.

examples

Examples

iex>Polyn.Sandbox.allow(self(), Process.whereis(:foo))
:ok

Returns a specification to start this module under a supervisor.

See Supervisor.

@spec get!(pid()) :: pid()

Get the nats server for a given pid

@spec get_async_mode() :: boolean()

Get the async mode of the Sandbox. Defaults to false

@spec set_async_mode(mode :: boolean()) :: :ok

Make the sandbox async false or true

Link to this function

setup_test(test_pid, nats_pid)

View Source
@spec setup_test(test_pid :: pid(), nats_pid :: pid()) :: :ok

Setup a test with a mock nats server association

Link to this function

start_link(initial_value)

View Source
@spec start_link(any()) :: Agent.on_start()

Start the Sandbox

@spec state() :: map()

Get the full state

@spec teardown_test(test_pid :: pid()) :: :ok

Remove the nats server assocation when a test is finished