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

Switch to nimble_ownership #148

Merged
merged 10 commits into from
Jan 21, 2024
Merged

Switch to nimble_ownership #148

merged 10 commits into from
Jan 21, 2024

Conversation

whatyouhide
Copy link
Collaborator

WIP, we need to publish a new version of nimble_ownership 🙃

@@ -44,14 +44,16 @@ defmodule Mox.Server do
# Callbacks

def init(:ok) do
{:ok, os} = NimbleOwnership.start_link([])
Copy link
Member

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? 🤔

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
Copy link
Member

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?

lib/mox/server.ex Outdated Show resolved Hide resolved
@whatyouhide
Copy link
Collaborator Author

@josevalim done with global mode and no more process in Mox.Server. I left the Mox.Server module because it's a nice boundary IMO still.

@josevalim
Copy link
Member

I think we should totally remove the server, if there is no need. :)

@whatyouhide whatyouhide changed the title Switch to nimble_ownership Switch to nimble_ownership Jan 20, 2024
@whatyouhide
Copy link
Collaborator Author

@josevalim ok, 200 lines less and removed Mox.Server completely... worth it 🙃

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}})
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

Copy link
Member

@josevalim josevalim left a 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. :)

@whatyouhide whatyouhide merged commit e380c96 into master Jan 21, 2024
2 checks passed
@whatyouhide whatyouhide deleted the al/nimble-ownership branch January 21, 2024 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants