Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

with_testing_mode is ignored if enqueuing within another process #1067

Closed
benschenker opened this issue Apr 15, 2024 · 1 comment
Closed
Labels
area:oss Related to Oban OSS kind:enhancement New feature or request

Comments

@benschenker
Copy link

benschenker commented Apr 15, 2024

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 sorentwo added kind:enhancement New feature or request area:oss Related to Oban OSS labels Apr 16, 2024
@sorentwo
Copy link
Member

@benschenker Great callout! This is handled now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:oss Related to Oban OSS kind:enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants