jtompl

jtompl

Can I automatically set infinite db timeout when in ExUnit trace mode?

When debugging with IEx.pry(), I got used to that I have to run my tests with a special command iex -S mix test --trace ... (otherwise, pry won’t even start, or test cases will timeout too soon).

Unfortunately, that’s not enough when you’re debugging an Ecto-based app/library. If you use the pry debugger during a db transaction, it will timeout, because default Ecto db timeout is 15 s. Thus, when debugging you also have to remember about manually changing your repos db timeout config. Otherwise you’ll see errors like Postgrex.Protocol (#PID<0.16080.0>) disconnected: ** (DBConnection.ConnectionError) client #PID<0.16746.0> timed out because it queued and checked out the connection for longer than 15000m while debugging and you’ll have to restart the whole test process.

That annoys me! Such manual steps make debugging harder than it should be.

Can I “detect” anyhow that I’m in a mix test --trace mode? Why don’t we change default Ecto timeout settings in such a case to :infinity for all the users in test trace mode?

P.S. The current workaround we found for this problem is to add the following into config/test.exs:

config :my_app, MyApp.Repo,
  timeout:
    (if(System.get_env("CI")) do
       15000
     else
       :infinity
     end),
  ownership_timeout:
    (if(System.get_env("CI")) do
       120_000
     else
       :infinity
     end)

This isn’t perfect yet though, as it’ll make the db timeout infinite also when you’re not in a trace mode. (I don’t know how can I detect “am I in trace mode?”.)

First Post!

LostKobrakai

LostKobrakai

You can probably look at ExUnit.configuration() in test_helpers.exs and reconfigure your repo with different timeouts than the default from there.

Where Next?

Popular in Discussions Top

JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 54921 245
New
sergio
There’s a new TIOBE index report that came out that shows Elixir is still not in the top 50 used languages. It also goes on to call Elix...
New
MarioFlach
Hello, I want to share a project I’ve been working on for a while: https://github.com/almightycouch/gitgud Background Some time ago I ...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 40042 209
New
lucaong
Hello Elixir and Nerves community, I have been working for a while on an open-source embedded key-value database for Elixir, that I call...
230 14350 124
New
klo
Got a question about when to concat vs. prepending items to list then reversing to achieve appending. So i know lists boil down to [1 | ...
New
fireproofsocks
I’ve been working on an Elixir project that has required a lot of scripting. I usually reach for Elixir because I like it more (and in th...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs &amp; Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 130286 1222
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New

We're in Beta

About us Mission Statement