`async: false` is the worst. Here's how to never need it again.
A common challenge when testing Elixir apps is dealing with shared/global state. When multiple tests modify/access the same piece of state, in order to ensure the tests don’t interfere with each other, we need to serialize the tests using async: false
.
To isolate tests from each other and avoid async: false
, here we explore a technique for “localizing” global state. That is, we reduce the scope of in-memory state such that each ExUnit test has its own private copy of the state. With global state thus localized, our ExUnit tests are decoupled and safe for async: true
.