Ecto.Adapters.SQL.Sandbox.mode
mode
, go back to Ecto.Adapters.SQL.Sandbox module for more information.
Sets the mode for the repo
pool.
The modes can be:
:auto
- this is the default mode. When trying to use the repository, processes can automatically checkout a connection without callingcheckout/2
orstart_owner/2
before. This is the mode you will run on before your test suite starts:manual
- in this mode, the connection always has to be explicitly checked before used. Other processes are allowed to use the same connection if they are explicitly allowed viaallow/4
. You usually set the mode to manual at the end of yourtest/test_helper.exs
file. This is also the mode you will run your async tests in{:shared, pid}
- after checking out a connection in manual mode, you can change the mode to{:shared, pid}
, where pid is the process that owns the connection, most often{:shared, self()}
. This makes it so all processes can use the same connection as the one owner by the current process. This is the mode you will your sync tests in
Whenever you change the mode to :manual
or :auto
, all existing
connections are checked in. Therefore, it is recommend to set those
modes before your test suite starts, as otherwise you will check in
connections being used in any other test running concurrently.