Specify pool_size in Ecto.Adapters.SQL.Sandbox

I have an application which is running a large number of GenStage pipelines. The addition of an additional pipeline has caused my test suite to from what appears to be poolboy failing to checkout a database connection.

Is there any way to increase the pool_size used in the sandbox adapter by passing an argument to DBConnection.PoolBoy? The docs only specify providing the ownership_timeout option.

Or am I going down the wrong path and my architecture is wrong :grimacing:. It seems like I should be able to support lots of concurrent supervised pipelines.

I get the following stacktrace when starting my tests:

23:51:01.967 [error] GenServer #PID<0.1063.0> terminating
** (stop) exited in: :gen_server.call(#PID<0.841.0>, {:checkout, #Reference<0.114150210.3257925636.74669>, true}, 5000)
    ** (EXIT) time out
    (stdlib) gen_server.erl:214: :gen_server.call/3
    (poolboy) src/poolboy.erl:55: :poolboy.checkout/3
    (db_connection) lib/db_connection/poolboy.ex:41: DBConnection.Poolboy.checkout/2
    (ecto) lib/ecto/adapters/sql/sandbox.ex:386: Ecto.Adapters.SQL.Sandbox.Pool.checkout/2
    (db_connection) lib/db_connection/ownership/proxy.ex:108: DBConnection.Ownership.Proxy.handle_call/3
    (stdlib) gen_server.erl:636: :gen_server.try_handle_call/4
    (stdlib) gen_server.erl:665: :gen_server.handle_msg/6
    (stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3
Last message (from #PID<0.1062.0>): {:init, 15000}

And then a subset of my tests fail with the following error:

** (MatchError) no match of right hand side value: {:error, %DBConnection.ConnectionError{message: "failed to checkout using Ecto.Adapters.SQL.Sandbox.Pool"}}

The Sandbox uses the same DBConnect.Pool behavior as the rest of Ecto … so hopefully you can just add a pool_size entry to your Repo configuration in config/test.exs (or wherever you are keeping your test configuration) and it should pick it up.

2 Likes

Yup, that did it. Thanks!