Ecto.Adapters.SQL.Sandbox.mode

You're seeing just the function 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 calling checkout/2 or start_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 via allow/4. You usually set the mode to manual at the end of your test/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.