Default value for ExUnit.Case async

I always thought that the default value for ExUnit.Case, async was true. However in a recent video from ElixirCasts the author states otherwise:

Am I mistaken?
Do I need to use ExUnit.Case, async: true if I want concurrent tests?

I couldn’t find anything in the official docs:

https://hexdocs.pm/ex_unit/ExUnit.html

Looks like it default to false https://github.com/elixir-lang/elixir/blob/3a3d68385ef02148136ff4b9490c70d3e6d3dbc3/lib/ex_unit/lib/ex_unit/case.ex#L218

2 Likes

ExUnit.Case — ExUnit v1.16.0

2 Likes

It defaults to false like it should. Elixir doesn’t know whether your test depends on some possibly hidden global state or not. Having async: true could cause some of your tests to fail in unpredictable ways which would be hard to debug.

I’d prefer it to default to concurrent, to nudge us into writing code that is safe to run concurrently by default :slight_smile:

2 Likes

The problem is that async: true does something different from what people may expect. Tests in single module are always run synchronously, no deviations. async: true mean that tests in given module can be ran in parallel with other modules. So this would produce unexpected results when used with some persistent storage tools, when used without special preparations, or other hard to reason problems. Instead they have chosen to “safer default”. If you want to check your code for concurrency errors then you can check out Concuerror.

9 Likes