Skip to content

Commit

Permalink
Use $callers, not $ancestors for inline check
Browse files Browse the repository at this point in the history
We care about Tasks for inline testing checks, not normal supervision
tree ancestry. The $callers entry is the appropriate mechanism to find
the [trail of calling processes][trail]:

[trail]: https://hexdocs.pm/elixir/1.16.2/Task.html#module-ancestor-and-caller-tracking
  • Loading branch information
sorentwo committed Apr 22, 2024
1 parent d5b2e89 commit 0abfe77
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 6 deletions.
6 changes: 2 additions & 4 deletions lib/oban/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ defmodule Oban.Config do
def get_engine(%__MODULE__{engine: engine, testing: :disabled}), do: engine

def get_engine(%__MODULE__{engine: engine, testing: testing}) do
pids = [self() | Process.get(:"$ancestors", [])]
pids = [self() | Process.get(:"$callers", [])]

if Enum.any?(pids, &inline_testing?(&1, testing)) do
Oban.Engines.Inline
Expand All @@ -163,14 +163,12 @@ defmodule Oban.Config do
end
end

defp inline_testing?(pid, default) when is_pid(pid) do
defp inline_testing?(pid, default) do
{:dictionary, dictionary} = Process.info(pid, :dictionary)

Keyword.get(dictionary, :oban_testing, default) == :inline
end

defp inline_testing?(_pid, _default), do: false

@doc false
@spec node_name(%{optional(binary()) => binary()}) :: binary()
def node_name(env \\ System.get_env()) do
Expand Down
2 changes: 0 additions & 2 deletions test/oban/testing_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,6 @@ defmodule Oban.TestingTest do

Testing.with_testing_mode(:inline, fn ->
fun = fn ->
Process.put(:"$ancestors", [Some.Endpoint | Process.get(:"$ancestors")])

Oban.insert!(name, Worker.new(%{ref: 1, action: "OK"}))

assert_received {:ok, 1}
Expand Down

0 comments on commit 0abfe77

Please sign in to comment.