On 20/05/14 20:58, Peter Hamilton wrote:
> Would you ever not want it guaranteed?
When I know my cleanup will only be needed when the process still
exists. E.g. cleaning up process dictionary or ets tables.
On 20/05/14 20:59, José Valim wrote:
> Maybe it is worthy deprecating teardown? A teardown that does not run
> all the time is not really useful...
IMO teardown is a well known pattern and I'd expect it to be there in
ExUnit for all the cases where I only need teardown and no setup.
I originally expected teardown to simply be guaranteed to run. I thought
ExUnit would just run it in-process or in a newly spawned one, but it
would definitely always run it.
On 20/05/14 21:00, José Valim wrote:
> Well maybe we could just fix teardown and make it clear it runs in
> another process... the on_exit feature though is interesting because
> we could register things dynamically, for example, only if a
> particular feature is used.
Agreed. Both features are useful IMO. I think having even more options
on teardown might be worth it. Consider some use cases:
1. Cleaning up process dictionary or ets tables: Don't care if the
process died, don't need to run then.
If run in a different process and it e.g. does ets:all and then filters
by ets:info(owner) or does :erlang.erase this might interfere with
ExUnit (or whichever process it is run in).
2. Rolling back an open Postgres connection: This needs to run but
doesn't especially care about the process it's run in (as long as it can
get at the Postgres connection) Also it needs to know if the setup hook
actually ran.
3. Killing spawned processes: This doesn't care where it runs (since it
would just do :gen_server.call(:some_name, :die) or Process.exit/2
And how about an around hook? (with yield ;) )