Most of the processes in our system wait for a request, do some processing, possibly a state update, and then send out more requests - most of the time not to the requestor but to another entity. The system is more like a middle man between two entities, terminating protocols on both sides.
The processes are registered with :gproc
, so I had the glorious idea that in unit tests we can simply register the test case itself as the recipient for a given name or property and wait if we receive the expected messages once we stimulate our process or not. On timeout, we fail instead. It looks like this:
test "foo" do
{:ok, pid} = bar.start
Process.monitor(pid)
:gproc.reg({:n, :l, :actual_recipient})
send(pid, :example_message)
result = receive do
:example_reply -> :pass
after 10 -> :fail
end
assert result == :pass
end
This was all fine and dandy… but not when you run tests in parallel. Several might register for the same name in :gproc
and so this approach to testing works with parallel testing set to off.
How do you test such processes?
Can maybe each ExUnit.Case be run in its own node to remove the problem (with async: false
) while being able to run suites in parallel?