-
Notifications
You must be signed in to change notification settings - Fork 77
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
Switch to nimble_ownership
#148
Conversation
lib/mox/server.ex
Outdated
@@ -44,14 +44,16 @@ defmodule Mox.Server do | |||
# Callbacks | |||
|
|||
def init(:ok) do | |||
{:ok, os} = NimbleOwnership.start_link([]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we start it on mox supervision tree with a given name? 🤔
lib/mox/server.ex
Outdated
state = maybe_revalidate_lazy_calls(lazy_calls, state) | ||
owner_pid = | ||
case NimbleOwnership.get_owner(state.os, caller_pids, mock) do | ||
%{owner_pid: owner_pid} -> owner_pid |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can the owner_pid be nil? If not, shouldn't we merge the conditional below into this function?
bd39ee4
to
f953af4
Compare
@josevalim done with global mode and no more process in |
I think we should totally remove the server, if there is no need. :) |
@josevalim ok, 200 lines less and removed |
lib/mox.ex
Outdated
case N.fetch_owner(@ownership_server, [owner_pid], mock, @timeout) do | ||
{tag, ^owner_pid} when tag in [:ok, :shared_owner] -> :ok | ||
{:shared_owner, other_owner} -> throw({:error, {:not_shared_owner, other_owner}}) | ||
{:ok, other_owner} -> throw({:error, {:currently_allowed, other_owner}}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not use throw? If we encapsulate this into a private function, using with
should be straight-forward.
lib/mox.ex
Outdated
case N.fetch_owner(@ownership_server, caller_pids, mock, @timeout) do | ||
{tag, owner_pid} when tag in [:shared_owner, :ok] -> owner_pid | ||
:error -> throw(:no_expectation) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolutely beautiful, just two tiny comments. :)
WIP, we need to publish a new version of nimble_ownership 🙃