       |> Enum.map_join(@indent, fn {name, var} -> "#{name} = #{inspect(var)}" end)
 
     "\nThe following variables were pinned:" <> @indent <> content
+  end
+
+  defp format_mailbox(messages) do
+    length = length(messages)
+
+    mailbox =
+      messages
+      |> Enum.take(@max_mailbox_length)
+      |> Enum.map_join(@indent, &inspect/1)
+
+    mailbox_message(length, @indent <> mailbox)
   end
 
   defp mailbox_message(0, _mailbox), do: "\nThe process mailbox is empty."

        "expected:\n  #{inspect(message)}\n" <>
        "actual:\n" <> "  #{inspect(Exception.message(error))}"

    assert match?, message: message

    error
  end

  @max_mailbox_length 10

  @doc false
  def __timeout__(timeout) when is_integer(timeout) and timeout >= 0, do: timeout

  def __timeout__(timeout),
    do: raise(ArgumentError, "timeout must be a non-negative integer, got: #{inspect(timeout)}")

  @doc false
  def __timeout__(binary, pins, pattern_finder, timeout) do
    {:messages, messages} = Process.info(self(), :messages)

    if Enum.any?(messages, pattern_finder) do
      """
      Found message matching #{binary} after #{timeout}ms.

      This means the message was delivered too close to the timeout value, you may want to either:

        1. Give an increased timeout to `assert_receive/2`
        2. Increase the default timeout to all `assert_receive` in your
           test_helper.exs by setting ExUnit.configure(assert_receive_timeout: ...)
      """
    else
      "No message matching #{binary} after #{timeout}ms." <>
        __pins__(pins) <> format_mailbox(messages)
    end
  end

  @doc false
