kura_sandbox (kura v1.19.2)
View SourceTest sandbox that wraps each test in a rolled-back transaction.
Supports three modes:
Single-process (default) — the test process owns the connection:
init_per_testcase(_TestCase, Config) ->
kura_sandbox:checkout(my_repo),
Config.
end_per_testcase(_TestCase, _Config) ->
kura_sandbox:checkin(my_repo),
ok.Allow — let spawned processes share the sandbox connection:
kura_sandbox:checkout(my_repo),
kura_sandbox:allow(my_repo, self(), WorkerPid).Shared — all processes use a single sandbox connection (simplest for tests that spawn many processes):
kura_sandbox:checkout(my_repo, #{shared => true}).All database operations within the sandbox are rolled back on checkin. No test data persists.
Summary
Functions
Allow ChildPid to use OwnerPid's sandbox connection.
Roll back the sandbox transaction and return the connection to the pool.
Check out a sandbox connection with default options.
Check out a sandbox connection.
Look up a sandbox connection for the current process and pool.
Create the sandbox ETS table. Call once before tests run.
Functions
Allow ChildPid to use OwnerPid's sandbox connection.
The child process must call this before making any database queries.
-spec checkin(module()) -> ok.
Roll back the sandbox transaction and return the connection to the pool.
-spec checkout(module()) -> ok.
Check out a sandbox connection with default options.
Check out a sandbox connection.
Options:
shared— whentrue, all processes use this connection (default:false)
Look up a sandbox connection for the current process and pool.
Returns {ok, Conn} if a sandbox connection exists (owned, allowed,
or shared), not_found otherwise. Called from kura_repo_worker.
-spec start() -> ok.
Create the sandbox ETS table. Call once before tests run.