# somewhere during setup
Module.register_attribute(__MODULE__, :needs_trace, accumulate: true)
defmacro assert_pid_receive(pid, message, timeout \\ 5000) do
quote do
Module.put_attribute(__MODULE__, :needs_trace, __EX_UNIT_TEST_NAME__)
receive do
{:trace, unquote(pid), :receive, unquote(message)} ->
:ok
after
unquote(timeout) ->
{:error, :timeout}
end
end
# somewhere in test process bootstrap
if (__EX_UNIT_TEST_NAME__ in @needs_trace) do
:erlang.trace(:processes, true, [:receive])
end
fixed the formatting
On Tuesday, June 2, 2020 at 1:26:40 PM UTC-7, Adam Lancaster wrote:
>
> It would be great if we could expose a function that allowed us to say
> something like this:
>
> defmodule MyGen do
> use GenServer
>
> @impl true
> def init(data) do
> {:ok, data}
> end
>
> end
>
> {:ok, pid} = MyGen.start_link(MyGen, :hi)
>
> assert_receive(pid, :hello)
>
>
>
>
> I recently learned you can do something like this:
>
> :erlang.trace(pid, true, [:receive])
>
> So I wondered if that or :erlang.trace_delivered may be helpful here.
>
> Best
>
> Adam
>
>
--
You received this message because you are subscribed to the Google Groups
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/elixir-lang-core/a5e8d000-bb01-42be-b688-99d497dbae7f%40googlegroups.com.