You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Say I want to trap exits from this genserver. In IEX, it works fine:
iex> Process.flag :trap_exit, true
iex> {:ok, pid} = GenServer.start_link Foo, nil
iex> GenServer.call(pid, :whatever)
** logs a bunch of stuff but doesn't crash IEx
iex> flush()
{:EXIT, ...}
If I do this in an ExUnit test though, the test crashes:
defmoduleFooTestdouseExUnit.Casetest"foo shouldn't crash"doProcess.flag:trap_exit,true{:ok,pid}=GenServer.start_linkFoo,nilGenServer.call(pid,:whatever)assert_receive{:EXIT,_,_}# crashes before arriving hereendend
What do you think? Also, I made a small Mix project that shows this behaviour (here), if you want you can clone it and run mix test to see it fail, then iex -S mix with the commands above to see exits are trapped indeed.
The text was updated successfully, but these errors were encountered:
It's not a bug. If the process exits during a GenServer.call the call will raise [1]. You can try wrapping the call in catch_exit/1 and asserting on that.
I'm not sure if this a bug or if I'm doing something wrong. Assume the following GenServer:
Say I want to trap exits from this genserver. In IEX, it works fine:
If I do this in an ExUnit test though, the test crashes:
What do you think? Also, I made a small Mix project that shows this behaviour (here), if you want you can clone it and run
mix test
to see it fail, theniex -S mix
with the commands above to see exits are trapped indeed.The text was updated successfully, but these errors were encountered: