Skip to content

Commit

Permalink
Improve more and more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
whatyouhide committed Oct 12, 2023
1 parent f7f8fb8 commit 427d576
Show file tree
Hide file tree
Showing 4 changed files with 529 additions and 588 deletions.
3 changes: 2 additions & 1 deletion lib/xandra/cluster.ex
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,8 @@ defmodule Xandra.Cluster do
@doc false
@spec child_spec(keyword()) :: Supervisor.child_spec()
def child_spec(options) do
%{id: __MODULE__, start: {__MODULE__, :start_link, [options]}}
id = Keyword.get(options, :name, __MODULE__)
%{id: id, start: {__MODULE__, :start_link, [options]}, type: :worker}
end

@doc """
Expand Down
26 changes: 3 additions & 23 deletions lib/xandra/cluster/pool.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,12 @@ defmodule Xandra.Cluster.Pool do
gen_statem_opts
) do
{:ok, pid} when is_integer(sync_connect_timeout) ->
ref = Process.monitor(pid)

receive do
{^sync_connect_alias_or_nil, :connected} ->
Process.demonitor(ref, [:flush])
{:ok, pid}

{:DOWN, ^ref, _, _, reason} ->
if sync_connect_alias_or_nil, do: Process.unalias(sync_connect_alias_or_nil)
exit(reason)
after
sync_connect_timeout ->
if sync_connect_alias_or_nil, do: Process.unalias(sync_connect_alias_or_nil)
Process.demonitor(ref, [:flush])
{:error, :sync_connect_timeout}
end

Expand Down Expand Up @@ -194,15 +186,6 @@ defmodule Xandra.Cluster.Pool do
end
end

def handle_event(
:internal,
:flush_queue_before_connecting,
_state = :has_connected_once,
%__MODULE__{reqs_before_connecting: nil}
) do
{:keep_state_and_data, timeout_action(:flush_queue_before_connecting, :infinity)}
end

def handle_event(
:internal,
:flush_queue_before_connecting,
Expand All @@ -225,13 +208,10 @@ defmodule Xandra.Cluster.Pool do
_state = :never_connected,
%__MODULE__{} = data
) do
froms =
case data.reqs_before_connecting do
nil -> []
%{queue: queue} -> :queue.to_list(queue)
end
actions =
for from <- :queue.to_list(data.reqs_before_connecting.queue),
do: {:reply, from, {:error, :empty}}

actions = for from <- froms, do: {:reply, from, {:error, :empty}}
data = put_in(data.reqs_before_connecting, nil)

{:keep_state, data, actions}
Expand Down
Loading

0 comments on commit 427d576

Please sign in to comment.