def assert_receive_all([]), do: :okdef assert_receive_all(messages) doreceive domsg ->assert Enum.member?(messages, msg) # The message we received should be one of the expected ones.messages = List.delete(messages, msg)assert_receive_all(messages)after100 ->raise ExUnit.AssertionError,expr: messages,message: "Did not receive all expected messages before timeout.":timeoutendendAnd here's an example of how it's used:# Verifies that these two messages are received, in any order, and nothing else.assert_receive_all([{:child, "Zebra"},{:infomesh, {:ecommons, :ooc}, "Cats"}])Is there a better or pre-existing way to test for this sort of thing? If not, should we consider putting something like this into ExUnit?
10 ->
Something like this should work:
defmacro assert_receive_all(messages) do
Enum.map(messages, fn msg ->
quote do: assert_receive(unquote(msg))
end)
end
--
You received this message because you are subscribed to the Google Groups "elixir-lang-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-ta...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-talk/f4f11b3c-4869-4ebd-810d-35ec5a505e29%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
assert_receive {:child, "Zebra"}assert_receive {:infomesh, {:ecommons, :ooc}, "Cats"}refute_receive _