Skip to content

Commit 8b7cd3d

Browse files
authored
fix: Support registered names in mock (#683)
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.
1 parent f1c9a36 commit 8b7cd3d

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

lib/tesla/mock.ex

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,11 @@ defmodule Tesla.Mock do
233233
Enum.find(Process.get(:"$ancestors", []), self(), fn ancestor ->
234234
!is_nil(Process.get(ancestor, __MODULE__))
235235
end)
236+
|> case do
237+
nil -> raise "Unknown pid_holder in mock"
238+
pid when is_pid(pid) -> pid
239+
name when is_atom(name) -> Process.whereis(name)
240+
end
236241

237242
pid_holder |> Process.info() |> Keyword.get(:dictionary) |> Keyword.get(__MODULE__)
238243
end

0 commit comments

Comments
 (0)