sorentwo/oban

Add `crontab: false` to recommended test config

Closed this issue · 5 comments

Is your feature request related to a problem? Please describe.

As a recent user of oban, I followed the very nice setup docs and was suprised to see the following errors when running my test suite:

10:28:38.447 [error] Postgrex.Protocol (#PID<0.441.0>) disconnected: ** (DBConnection.ConnectionError) #PID<0.98.0> checked in the connection owned by #PID<0.483.0>

#PID<0.98.0> triggered the checkin at location:

    test/test_helper.exs:2: (file)
    (elixir 1.16.2) src/elixir_compiler.erl:67: :elixir_compiler.dispatch/4
    (elixir 1.16.2) src/elixir_compiler.erl:52: :elixir_compiler.compile/4
    (elixir 1.16.2) src/elixir_compiler.erl:39: :elixir_compiler.maybe_fast_compile/3
    (elixir 1.16.2) src/elixir_lexical.erl:15: :elixir_lexical.run/3
    (elixir 1.16.2) src/elixir_compiler.erl:17: :elixir_compiler.quoted/3


Client #PID<0.483.0> is still using a connection from owner at location:

    (erts 14.2.2) :prim_inet.recv0/3
    (postgrex 0.17.5) lib/postgrex/protocol.ex:3197: Postgrex.Protocol.msg_recv/4
    (postgrex 0.17.5) lib/postgrex/protocol.ex:2222: Postgrex.Protocol.recv_bind/3
    (postgrex 0.17.5) lib/postgrex/protocol.ex:2077: Postgrex.Protocol.bind_execute_close/4
    (db_connection 2.6.0) lib/db_connection/holder.ex:354: DBConnection.Holder.holder_apply/4
    (db_connection 2.6.0) lib/db_connection.ex:1512: DBConnection.run_execute/5
    (db_connection 2.6.0) lib/db_connection.ex:1607: DBConnection.run/6
    (db_connection 2.6.0) lib/db_connection.ex:743: DBConnection.parsed_prepare_execute/5

The connection itself was checked out by #PID<0.483.0> at location:

    (postgrex 0.17.5) lib/postgrex.ex:363: Postgrex.query_prepare_execute/4

The errors did not result in a failure of the test suite, which was somehow less reassuring than a regular failure.

I read through the issue history on the repo and found #123 which appears to describe the behavior I am observing. I tried the recommended change (add crontab: false to the test oban config), and that caused the nonfatal postgrex errors to disappear. Success! However, this seems like something that ought to be mentioned in the installation docs so that new users don't have to travel the same road.

Describe the Solution You'd Like

I think that the installation guide should recommend adding crontab: false to the test Oban configuration.

Describe Alternatives You've Considered

It might also work to add an explanatory paragraph at that point discussing the pros and cons of adding this option, but it would increase the friction of the installation process and probably wouldn't be relevant for a new user.

Additional Context

My environment:

  • Erlang/OTP 26 [erts-14.2.2] [source] [64-bit] [smp:10:10] [ds:10:10:10] [async-threads:1] [jit]
  • Elixir 1.16.2 (compiled with Erlang/OTP 26)
  • macOS Sonoma 14.2.1

The crontab option is long deprecated, and it translates into Oban.Plugins.Cron for backward compatibility. To disable crontabs in testing you can set plugins: false, but the proper way to configure tests is with the testing option, e.g. testing: :manual.

The testing options are described in the testing guide.

Note, the issue you linked to is for Oban v0.12, and we're on v2.17 now 🙂

Thanks for the quick reply! I do see now that the option is deprecated, so it makes sense that it shouldn't be in the installation guide.

Does this also mean that the errors I encountered are to be expected when using testing: :inline? That seems like it might be worth noting in the README or in one of the guides.

No, you shouldn’t have any connection errors with inline either. Will you test with main and see if that fixes the issue for you?

No, you shouldn’t have any connection errors with inline either. Will you test with main and see if that fixes the issue for you?

After confirming the presence of the error messages in my branch, I switched the mix ref to main and re-ran my test suite. Whereas before I was seeing the errors in about 50% of the test runs, after the switch to main I observed the errors in 0 / 10 runs. Based on that observation, it looks like a change in main (after the last release) fixed my problem. Thanks for suggesting that test!

@fastjames Thanks for reporting back. Oban v2.17.7 is out now with the fix you tested in main.