View Source Polyn.Sandbox (Polyn v0.3.0)
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
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
.
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
Setup a test with a mock nats server association
@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