defmodule SyncSchedulerWorker do
use GenServer
def start_link(_) do
GenServer.start_link(__MODULE__, [], name: __MODULE__)
end
@impl true
def init(state) do
schedule_work()
{:ok, state}
end
@impl true
def handle_info(:work, _state) do
schedule_work()
{:noreply, start_background_jobs()}
end
defp schedule_work, do: Process.send_after(self(), :work, :timer.hours(1))
defp start_background_jobs() do
for org <- Orgs.list_syncable_organizations() do
{:ok, _job} = Oban.insert(SyncWorker.new(%{organization_id: org.id}))
end
end
end
And the following test:
defmodule SyncSchedulerWorkerTest do
use App.DataCase
test "without syncable organizations" do
# PASSES
pid = Process.whereis(SyncSchedulerWorker)
send(pid, :work)
refute_enqueued(worker: SyncWorker)
end
test "with syncable organizations" do
# FAILS
%{id: id} = Fixtures.organization()
pid = Process.whereis(SyncSchedulerWorker)
send(pid, :work)
assert_enqueued([worker: SyncWorker, args: %{organization_id: id}], 5_000)
end
end
The second test fails with the error:
11:48:36.727 [error] GenServer SyncSchedulerWorker terminating
** (ArgumentError) errors were found at the given arguments:
* 1st argument: not a pid
(erts 14.2.1) :erlang.process_info(Pulse.Supervisor, :dictionary)
(elixir 1.16.0) lib/process.ex:860: Process.info/2
(oban 2.17.9) lib/oban/config.ex:167: Oban.Config.inline_testing?/2
(elixir 1.16.0) lib/enum.ex:4202: Enum.predicate_list/3
(oban 2.17.9) lib/oban/config.ex:159: Oban.Config.get_engine/1
(oban 2.17.9) lib/oban/engine.ex:317: anonymous fn/3 in Oban.Engine.with_span/4
(telemetry 1.2.1) /xxx/deps/telemetry/src/telemetry.erl:321: :telemetry.span/3
(pulse 1.0.0) lib/app/sync_scheduler_worker.ex:25: anonymous fn/1 in SyncSchedulerWorker.start_background_jobs/0
(elixir 1.16.0) lib/enum.ex:1700: Enum."-map/2-lists^map/1-1-"/2
(pulse 1.0.0) lib/app/sync_scheduler_worker.ex:18: SyncSchedulerWorker.handle_info/2
(stdlib 5.2) gen_server.erl:1095: :gen_server.try_handle_info/3
(stdlib 5.2) gen_server.erl:1183: :gen_server.handle_msg/6
(stdlib 5.2) proc_lib.erl:241: :proc_lib.init_p_do_apply/3
Last message: :work
Oban is configured as follows in test.exs:
config :app, Oban, testing: :manual
Expected Behavior
The test passes on versions prior to 2.17.9. It should pass with 2.17.9 as well.
Environment
elixir --version
): 1.16 OTP 26Current Behavior
Given the following GenServer:
And the following test:
The second test fails with the error:
Oban is configured as follows in
test.exs
:Expected Behavior
The test passes on versions prior to 2.17.9. It should pass with 2.17.9 as well.
Other
Could be related to changes for https://github.com/sorentwo/oban/issues/1067?