在 CircleCI 测试期间增加 Postgrex 数据库超时

Increase Postgrex database timeout during CircleCI tests

我 运行 遇到 mix test 在 CircleCI 上偶尔失败并出现以下错误的问题:

16:46:05.935 [error] Postgrex.Protocol (#PID<0.9303.0>) disconnected: ** (DBConnection.ConnectionError) owner #PID<0.73.0> timed out because it owned the connection for longer than 15000ms

我尝试将测试配置中的超时时间增加到:

config :my_app, MyApp.Repo,
  adapter: Ecto.Adapters.Postgres,
  database: System.get_env("DB_NAME"),
  username: System.get_env("DB_USER"),
  password: System.get_env("DB_PASS"),
  hostname: System.get_env("DB_HOST"),
  pool: Ecto.Adapters.SQL.Sandbox,
  timeout: 30000

但是在 15000 毫秒后它仍然超时。我应该寻找其他设置吗?

这里需要增加ownership_timeout,而不是timeout。这记录在 Ecto.Adapters.SQL.Sandbox 的模块文档中 owner timed out because it owned the connection for longer than Nms:

部分

If you have a long running test (or you’re debugging with IEx.pry), the timeout for the connection ownership may be too short. You can increase the timeout by setting the :ownership_timeout options for your repo config in config/config.exs (or preferably in config/test.exs):