Skip to content

Commit

Permalink
What about now
Browse files Browse the repository at this point in the history
  • Loading branch information
whatyouhide committed Aug 7, 2023
1 parent d822601 commit dab85e1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
10 changes: 8 additions & 2 deletions lib/xandra/cluster.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
17 changes: 9 additions & 8 deletions test/xandra/cluster/ccm_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down Expand Up @@ -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]),
Expand Down

0 comments on commit dab85e1

Please sign in to comment.