gpt4 book ai didi

debugging - Elixir pry session 因数据库连接超时而中断

转载 作者:行者123 更新时间:2023-11-28 19:47:21 24 4
gpt4 key购买 nike

我很高兴关注 this advice关于如何运行 我的 Phoenix Controller 测试中的调试器:

  • 要求目标文件中有IEx
  • IEx.pry 添加到所需行
  • 在 IEx 中运行测试:iex -S mix test --trace

但几秒钟后,这个错误总是出现:

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

如消息所述,此时数据库连接似乎超时,调用数据库连接的任何命令都将出错并返回 DBConnection.OwnershipError。我如何告诉我的数据库连接不要超时,以便我可以安静地调试我的测试?

最佳答案

Ecto.Adapters.SQL.Sandbox FAQ提到了这个问题并解释说您可以将 :ownership_timeout 设置添加到您的 Repo 配置中,以指定数据库连接在超时之前应保持打开状态的时间。我将我的设置为 10 分钟(仅限测试环境),这样我就不必再考虑它了:

# config.test.exs

config :rumbl, Rumbl.Repo,
# ...other settings...
ownership_timeout: 10 * 60 * 1000 # long timeout so pry sessions don't break

正如预期的那样,我现在可以在 pry 中闲逛 10 分钟,然后才会看到该错误。

关于debugging - Elixir pry session 因数据库连接超时而中断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40877651/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com