Packages

A distributed service registry built on top of phoenix_pubsub. Requests are dispatched to one or more services based on hashed keys.

Current section

Files

Jump to
dispatch test support helper.exs
Raw

test/support/helper.exs

defmodule Dispatch.Helper do
import ExUnit.Assertions
alias Dispatch.Registry
@rtype "TestDispatchType"
def setup_registry() do
if Process.whereis(Registry), do: Process.unregister(Registry)
if Process.whereis(Registry.HashRing), do: Process.unregister(Registry.HashRing)
{:ok, registry_pid} = Registry.start_link([broadcast_period: 5_000,
max_silent_periods: 20,
name: Registry])
{:ok, _} = Dispatch.HashRingServer.start_link([name: Registry])
{:ok, registry_pid}
end
def clear_type(_type) do
if old_pid = Process.whereis(Registry) do
Process.exit(old_pid, :kill)
end
if old_pid = Process.whereis(Registry.HashRing) do
Process.exit(old_pid, :kill)
end
end
def wait_dispatch_ready(node \\ nil) do
if node do
assert_receive {:join, _, %{node: ^node, state: :online}}, 5_000
else
assert_receive {:join, _, %{node: _, state: :online}}, 5_000
end
end
def get_online_services(type \\ @rtype) do
Registry.get_services(Registry, type)
end
end