oban-bg/oban

Oban.Crontab.Scheduler warnings during tests

Closed this issue · 3 comments

Environment

  • Oban Version: 0.12.0
  • ObanWeb Version: 0.6.2
  • PostgreSQL Version: 10
  • Elixir & Erlang/OTP Versions: 1.8.1 / OTP 22

Current Behavior

When running model tests for something not related with Oban, these warnings appear randomly:

13:00:27.812 [error] Postgrex.Protocol (#PID<0.1122.0>) disconnected: ** (DBConnection.ConnectionError) #PID<0.92.0> checked in the connection owned by #PID<0.1133.0>

#PID<0.92.0> triggered the checkin at location:

    (kernel) code_server.erl:139: :code_server.call/1
    (elixir) src/elixir_compiler.erl:80: :elixir_compiler.dispatch/4
    (elixir) src/elixir_compiler.erl:63: :elixir_compiler.compile/3
    (elixir) src/elixir_lexical.erl:17: :elixir_lexical.run/2
    (elixir) src/elixir_compiler.erl:23: :elixir_compiler.quoted/2
    (elixir) lib/code.ex:767: Code.require_file/2
    (elixir) lib/enum.ex:769: Enum."-each/2-lists^foreach/1-0-"/2
    (elixir) lib/enum.ex:769: Enum.each/2


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

    (kernel) code_server.erl:139: :code_server.call/1
    (kernel) error_handler.erl:41: :error_handler.undefined_function/3
    (jason) lib/jason.ex:197: Jason.encode_to_iodata!/2
    (postgrex) lib/postgrex/type_module.ex:897: Postgrex.DefaultTypes.encode_params/3
    (postgrex) lib/postgrex/query.ex:75: DBConnection.Query.Postgrex.Query.encode/3
    (db_connection) lib/db_connection.ex:1148: DBConnection.encode/5
    (db_connection) lib/db_connection.ex:1246: DBConnection.run_prepare_execute/5
    (db_connection) lib/db_connection.ex:540: DBConnection.parsed_prepare_execute/5

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

    (oban) lib/oban/crontab/scheduler.ex:94: Oban.Crontab.Scheduler.lock_and_enqueue/1

I have this in config/test.exs

config :my_app, Oban, queues: false, prune: :disabled

config :my_app, ObanWeb, stats: false

Expected Behavior

Not seeing these warnings.

Proposed fix

adding the crontab: [] option in config/test.exs seems to fix the issue:

config :my_app, Oban, queues: false, prune: :disabled, crontab: []

But I wanted to ensure this is the best solution, in this case it would be good to document this.

Related: #109

This was fixed on master about a week ago with 57cc89a. It will be in the 0.12.1 release out later today.

Oh, of note: you need to use crontab: false to clear the config. Mix deep merges configs, so an empty list in test.exs won't override what you have set in config.exs.