mbuhot / ecto_job

Transactional job queue with Ecto, PostgreSQL and GenStage
https://hexdocs.pm/ecto_job/
MIT License
277 stars 36 forks source link

DBConnection error when running test with :manual mode for sandbox #58

Open zacksiri opened 4 years ago

zacksiri commented 4 years ago

I have an application using EctoJob and it seems I'm getting errors when I'm using the manual sandbox mode.

This is very strange

because I have the same setup in another app and this is not happening.

I can't seem to find what's wrong

See Ecto.Adapters.SQL.Sandbox docs for more information.
    (ecto_sql) lib/ecto/adapters/sql.ex:626: Ecto.Adapters.SQL.raise_sql_call_error/1
    (ecto_sql) lib/ecto/adapters/sql.ex:562: Ecto.Adapters.SQL.execute/5
    (ecto) lib/ecto/repo/queryable.ex:177: Ecto.Repo.Queryable.execute/4
    (ecto_job) lib/ecto_job/producer.ex:184: EctoJob.Producer.dispatch_jobs/2
    (gen_stage) lib/gen_stage.ex:2103: GenStage.noreply_callback/3
    (stdlib) gen_server.erl:637: :gen_server.try_dispatch/4
    (stdlib) gen_server.erl:711: :gen_server.handle_msg/6
    (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
Last message: {:"$gen_producer", {#PID<0.427.0>, #Reference<0.3185423543.3099852806.167003>}, {:ask, 100}}
12:02:12.163 [error] GenServer #PID<0.427.0> terminating
** (DBConnection.OwnershipError) cannot find ownership process for #PID<0.426.0>.

test_helper.exs

ExUnit.start()

Ecto.Adapters.SQL.Sandbox.mode(Dispatch.Repo, :manual)

If I comment out the last line everything works.

strzibny commented 4 years ago

Same here, I can have one job queue in application.ex to start, but once I have two, or another process accessing the DB I got this error. For me this happens when running MIX_ENV=test mix ecto.reset, tests actually work.

mbuhot commented 4 years ago

I'm guessing this is caused by EctoJob accessing the Repo before your test_helper.exs file gets a chance to put the DB in sandbox mode?