Skip to content

Commit

Permalink
wip whereis
Browse files Browse the repository at this point in the history
  • Loading branch information
lud committed Sep 27, 2024
1 parent 0e42ca3 commit 947ad98
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/whereis_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,32 @@ defmodule Mutex.WhereisTest do
def start_link do
GenServer.start_link(__MODULE__, [], name: @via)
end

def init(init_arg) do
{:ok, init_arg}
end
def stop(pid) do
mref = Process.monitor(pid)
GenServer.cast(pid, :stop)
assert_receive {:DOWN, ^mref, :process, ^pid, :bye}
:ok
end

def handle_cast(:stop, state ) do
{:stop, :bye, state}
end
end

# server will start
assert {:ok, pid} = mod.start_link

Check warning on line 63 in test/whereis_test.exs

View workflow job for this annotation

GitHub Actions / OTP 26 / Elixir 1.17

using map.field notation (without parentheses) to invoke function Test_Mutex_613.start_link() is deprecated, you must add parentheses instead: remote.function()

# server will have a lock
assert {:error, :busy} = Mutex.lock(@mut, :gs)
assert {:error, {:already_started, ^pid}} = mod.start_link

# on stop the lock is freed (this does not need uregister_name impl, it's
# done by the monitor in the mutex anyway).
assert :ok = GenServer.stop(pid)
assert {:ok, _} = Mutex.lock(@mut, :gs)
end
end

0 comments on commit 947ad98

Please sign in to comment.