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
In tests, `import AsyncTest` and replace `test` with `async_test`:
26
+
In tests, `import AsyncTest` and replace `test`s with `async_test`s:
31
27
32
28
```diff
33
29
defmodule MyTest do
@@ -39,10 +35,19 @@ In tests, `import AsyncTest` and replace `test` with `async_test`:
39
35
+ async_test "my test" do
40
36
assert true
41
37
end
38
+
end
42
39
```
43
40
44
41
Now, all the `async_test`s will run asynchronously regardless of the module.
45
42
43
+
## Motivation
44
+
45
+
TL;DR Async tests in a single module may be harmful, thus ExUnit doesn't support them, but in particular cases they're beneficial.
46
+
47
+
ExUnit always runs tests in a single module synchronously (except of [parameterized tests](https://hexdocs.pm/ex_unit/ExUnit.Case.html#module-parameterized-tests)). [This PR](https://github.com/elixir-lang/elixir/pull/13283) was an attempt to change it, but, as described there, it didn't bring improvement to examined projects.
48
+
49
+
Sometimes, though, async tests in a single module help a lot. One example is [Boombox](https://github.com/membraneframework/boombox), where there's a lot of IO-bound, independent tests, and no reason to move them to different modules. Another one is [Popcorn](https://github.com/software-mansion/popcorn), where tests are CPU-bound, but also independent and very unevenly distributed across modules.
0 commit comments