Skip to content

Commit

Permalink
Raise on unknown conn opts when starting cluster (#361)
Browse files Browse the repository at this point in the history
  • Loading branch information
whatyouhide committed Mar 27, 2024
1 parent bee3984 commit 077cc5f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/xandra/cluster.ex
Expand Up @@ -329,6 +329,7 @@ defmodule Xandra.Cluster do
def start_link(options) when is_list(options) do
{cluster_opts, connection_opts} = Keyword.split(options, @start_link_opts_schema_keys)
cluster_opts = NimbleOptions.validate!(cluster_opts, @start_link_opts_schema)
connection_opts = NimbleOptions.validate!(connection_opts, Xandra.start_link_opts_schema())
Pool.start_link(cluster_opts, connection_opts)
end

Expand Down
6 changes: 6 additions & 0 deletions test/xandra/cluster_test.exs
Expand Up @@ -141,6 +141,12 @@ defmodule Xandra.ClusterTest do
Xandra.Cluster.start_link(nodes: ["example.com:9042"], name: "something something")
end
end

test "raises with an option that is not valid for the cluster and for the conn" do
assert_raise NimbleOptions.ValidationError, ~r"unknown options \[:port\]", fn ->
Xandra.Cluster.start_link(port: 9042)
end
end
end

describe "start_link/1" do
Expand Down
4 changes: 2 additions & 2 deletions test/xandra_test.exs
Expand Up @@ -234,12 +234,12 @@ defmodule XandraTest do
end)
|> Enum.map(fn {:ok, result} -> result end)

# The first and second calls succeeds, but the third call fails because it goes over
# The first call succeeds, but the second call fails because it goes over
# the max concurrent conns.
assert [
{1, {:ok, %Xandra.Page{}}},
{2, {:error, %ConnectionError{reason: :too_many_concurrent_requests} = error}}
] = results
] = Enum.sort_by(results, &elem(&1, 0))

assert Exception.message(error) =~ "this connection has too many requests in flight"
end
Expand Down

0 comments on commit 077cc5f

Please sign in to comment.