with_testing_mode is ignored if enqueuing within another process
Closed this issue · 1 comments
benschenker commented
Environment
{:oban, "~> 2.17.3"},
{:oban_pro, "~> 1.3.4", repo: "oban"},
{:oban_web, "~> 2.10.1", repo: "oban"},
- PostgreSQL Version: 16.1
- Elixir & Erlang/OTP Versions (
elixir --version
) Elixir 1.16.2 (compiled with Erlang/OTP 26)
Current Behavior
Given a test with the code:
Oban.Testing.with_testing_mode(:inline, fn ->
list
|> Task.async_stream(
fn el -> do_thing_and_enqueue_job(el) end,
max_concurrency: 5
)
|> Enum.map(fn {:ok, res} -> res end)
end)
and a config that sets the default testing to :manual
then the test fails with a timeout because the job never runs (it runs in :manual mode, ignoring the with_testing_mode)
Expected Behavior
Enqueuing a job within Task.async_stream would honor the testing mode specified in with_testing_mode. This issue would also be relevant with browser testing where the test process is different from the process that enqueues the job.
Workaround
Oban.Testing.with_testing_mode(:inline, fn ->
oban_testing_state = Process.get(:oban_testing)
list
|> Task.async_stream(
fn el ->
Process.put(:oban_testing, oban_testing_state)
do_thing_and_enqueue_job(el)
end,
max_concurrency: 5
)
|> Enum.map(fn {:ok, res} -> res end)
end)
Similarly it also works correctly when the work is done in the same process:
Oban.Testing.with_testing_mode(:inline, fn ->
list
|> Enum.map(fn el -> do_thing_and_enqueue_job(el) end)
end)
sorentwo commented
@benschenker Great callout! This is handled now.