Skip to content

Commit

Permalink
fix: Support registered names in mock (#683)
Browse files Browse the repository at this point in the history
In some situations, the pid_holder is a registered proces (e.g, MyApp.Supervisor).
Process.info/1 does not support this, so we have to use Process.whereis/1 to resolve the actual pid.

This small issue was introduced between 1.9 and 1.10.
  • Loading branch information
Raphexion authored Jun 19, 2024
1 parent f1c9a36 commit 8b7cd3d
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/tesla/mock.ex
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,11 @@ defmodule Tesla.Mock do
Enum.find(Process.get(:"$ancestors", []), self(), fn ancestor ->
!is_nil(Process.get(ancestor, __MODULE__))
end)
|> case do
nil -> raise "Unknown pid_holder in mock"
pid when is_pid(pid) -> pid
name when is_atom(name) -> Process.whereis(name)
end

pid_holder |> Process.info() |> Keyword.get(:dictionary) |> Keyword.get(__MODULE__)
end
Expand Down

0 comments on commit 8b7cd3d

Please sign in to comment.