I was happily following this advice on how to run a pry debugger inside my Phoenix controller tests:
require IEx
in the target fileIEx.pry
to the desired lineiex -S mix test --trace
But after a few seconds this error always appeared:
16:51:08.108 [error] Postgrex.Protocol (#PID<0.250.0>) disconnected:
** (DBConnection.ConnectionError) owner #PID<0.384.0> timed out because
it owned the connection for longer than 15000ms
As the message says, the database connection appears to time out at this point and any commands that invoke the database connection will error out with a DBConnection.OwnershipError
. How do I tell my database connection not to time out so I can debug my tests in peace?
The Ecto.Adapters.SQL.Sandbox FAQ mentions this issue and explains that you can add the :ownership_timeout
setting to your Repo config to specify how long db connections should stay open before timing out. I set mine to 10 minutes (test environment only) so I never have to think about it again:
# config.test.exs
config :rumbl, Rumbl.Repo,
# ...other settings...
ownership_timeout: 10 * 60 * 1000 # long timeout so pry sessions don't break
As expected, I can now fool around in pry
for 10 minutes before seeing that error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With