Show all messages in process mailbox assert_receive

Background

I am running a few tests and I want to make sure a process of mine receives a given message. Now the tests are failing, because assert_receive tells me I didn’t receive the proper message and then it shows me the last 10 messages.

Problem

But I don’t want to see the last 10, I want to see them all so I can pick the one I am interested in.

Question

  1. How can I make assert_receive show me all messages in the process mailbox when the assertion fails?
  2. If this is not possible, is it possible to have access to the process mailbox before the assert concludes and fails the test ?
1 Like

:wave:

If nothing else works out, you might be able to get all messages with :erlang.process_info(self(), :messages) before assert_receive.

test "..." do
  # ...
  messages = :erlang.process_info(self(), :messages)
  IO.inspect(messages, label: "messages")
  assert_receive :something
  # ...
end
4 Likes