diff --git a/lib/xandra/cluster.ex b/lib/xandra/cluster.ex index a74b21c6..74840131 100644 --- a/lib/xandra/cluster.ex +++ b/lib/xandra/cluster.ex @@ -334,7 +334,8 @@ defmodule Xandra.Cluster do # Internal for testing, not exposed. xandra_module: [type: :atom, default: Xandra, doc: false], control_connection_module: [type: :atom, default: ControlConnection, doc: false], - test_discovered_hosts: [type: :any, default: [], doc: false] + test_discovered_hosts: [type: :any, default: [], doc: false], + registry_listeners: [] ] @start_link_opts_schema_keys Keyword.keys(@start_link_opts_schema) @@ -633,7 +634,12 @@ defmodule Xandra.Cluster do registry_name = Module.concat([Xandra.ClusterRegistry, to_string(System.unique_integer([:positive]))]) - {:ok, _} = Registry.start_link(keys: :unique, name: registry_name) + {:ok, _} = + Registry.start_link( + keys: :unique, + name: registry_name, + listeners: Keyword.fetch!(cluster_opts, :registry_listeners) + ) # Start supervisor for the pools. {:ok, pool_sup} = Supervisor.start_link([], strategy: :one_for_one) diff --git a/test/xandra/cluster/ccm_test.exs b/test/xandra/cluster/ccm_test.exs index aa25e51d..93f9a6b6 100644 --- a/test/xandra/cluster/ccm_test.exs +++ b/test/xandra/cluster/ccm_test.exs @@ -23,9 +23,15 @@ defmodule Xandra.Cluster.CCMTest do ccm("start") ccm("status") + Process.register(self(), :this_test_process) + cluster = start_supervised!( - {Xandra.Cluster, nodes: ["127.0.0.1"], target_pools: 2, sync_connect: 5000} + {Xandra.Cluster, + nodes: ["127.0.0.1"], + target_pools: 2, + sync_connect: 5000, + registry_listeners: [:this_test_process]} ) wait_for_passing(5000, fn -> @@ -55,13 +61,8 @@ defmodule Xandra.Cluster.CCMTest do {{127, 0, 0, 3}, 9042} => %{host: _host3, status: :up} } = ctrl_conn_state.peers - assert [ - {{{registry_addr1, 9042}, 1}, _pid1, :up}, - {{{registry_addr2, 9042}, 1}, _pid2, :up} - ] = - cluster_state.registry - |> Registry.select([{{:"$1", :"$2", :"$3"}, [], [{{:"$1", :"$2", :"$3"}}]}]) - |> Enum.sort() + assert_receive {:register, _registry, {{registry_addr1, 9042}, 1}, _pid1, :up} + assert_receive {:register, _registry, {{registry_addr2, 9042}, 1}, _pid2, :up} assert MapSet.subset?( MapSet.new([registry_addr1, registry_addr2]),