Skip to content

Commit

Permalink
Fix bug with Scylla protocol (#346)
Browse files Browse the repository at this point in the history
  • Loading branch information
whatyouhide committed Oct 20, 2023
1 parent 459592f commit 67f54b0
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 14 deletions.
3 changes: 1 addition & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,9 @@ services:
context: ./test/docker
dockerfile: scylladb.dockerfile
args:
SCYLLA_VERSION: ${SCYLLA_VERSION:-5.1.6}
SCYLLA_VERSION: ${SCYLLA_VERSION:-5.2}
ports:
- "9062:9042"
- "10000:10000"
command:
- "--smp"
- "1"
Expand Down
2 changes: 1 addition & 1 deletion lib/xandra/connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ defmodule Xandra.Connection do
connect_timeout: Keyword.fetch!(options, :connect_timeout),
connection_name: Keyword.get(options, :name),
cluster_pid: Keyword.get(options, :cluster_pid),
protocol_version: Keyword.get(options, :protocol_version),
protocol_version: data.protocol_version || Keyword.get(options, :protocol_version),
options: options,
backoff:
data.backoff ||
Expand Down
98 changes: 89 additions & 9 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ defmodule Xandra.Mixfile do

# Testing
preferred_cli_env: [
"test.cassandra": :test,
"test.scylladb": :test,
"test.native_protocols": :test,
"test.all": :test,
"test.all_with_html_coverage": :test,
"coveralls.html": :test
],
test_coverage: [tool: ExCoveralls],
Expand Down Expand Up @@ -75,16 +78,45 @@ defmodule Xandra.Mixfile do
defp aliases() do
[
test: "test --exclude scylla_specific",
"test.scylladb": [
fn _args ->
System.put_env("CASSANDRA_PORT", "9062")
System.put_env("CASSANDRA_WITH_AUTH_PORT", "9063")
end,
"test --exclude cassandra_specific --exclude encryption --include scylla_specific"
],
"test.cassandra": fn args ->
print_header("Running Cassandra tests")

mix_cmd_with_status_check(
["test", "--exclude", "scylla_specific", ansi_option() | args],
[
{"CASSANDRA_PORT", "9052"},
{"CASSANDRA_WITH_AUTH_PORT", "9053"}
]
)
end,
"test.scylladb": fn args ->
print_header("Running ScyllaDB tests")

mix_cmd_with_status_check(
[
"test",
"--exclude",
"cassandra_specific",
"--exclude",
"encryption",
"--include",
"scylla_specific",
ansi_option() | args
],
[
{"CASSANDRA_PORT", "9062"},
{"CASSANDRA_WITH_AUTH_PORT", "9063"}
]
)
end,
"test.all": fn args ->
Mix.Task.run(:test, args)
Mix.Task.run(:"test.scylladb", args)
Mix.Task.run("test.cassandra", args)
Mix.Task.run("test.scylladb", args)
end,
"test.all_with_html_coverage": fn args ->
Mix.Task.run("test.cassandra", ["--cover", "--export-coverage", "cassandra" | args])
Mix.Task.run("test.scylladb", ["--cover", "--export-coverage", "scylla" | args])
Mix.Task.run("coveralls.html", ["--exclude", "test", "--import-cover", "cover"])
end,
docs: [
"run pages/generate_telemetry_events_page.exs",
Expand All @@ -109,4 +141,52 @@ defmodule Xandra.Mixfile do
{:toxiproxy_ex, github: "whatyouhide/toxiproxy_ex", only: :test}
]
end

defp mix_cmd_with_status_check(args, env) do
port =
Port.open({:spawn_executable, System.find_executable("mix")}, [
:binary,
:exit_status,
args: args,
env:
Enum.map(env, fn {key, val} ->
{String.to_charlist(key), String.to_charlist(val)}
end)
])

# We want a port so that we can shut down the port if we shut down the system.
receive_loop(port)
end

defp receive_loop(port) do
receive do
{^port, {:data, data}} ->
:ok = IO.write(data)
receive_loop(port)

{^port, {:exit_status, 0}} ->
:ok

{^port, {:exit_status, status}} ->
Mix.raise("Mix failed with exit status #{status}")
after
10_000 ->
Mix.raise("Timed out waiting for Mix to send back any data (after 10s)")
end
end

defp ansi_option do
if IO.ANSI.enabled?(), do: "--color", else: "--no-color"
end

defp print_header(header) do
Mix.shell().info([:cyan, :bright, header, :reset])

Mix.shell().info([
:cyan,
:bright,
String.duplicate("=", String.length(header)) <> "\n",
:reset
])
end
end
7 changes: 5 additions & 2 deletions test/xandra/cluster_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -341,16 +341,19 @@ defmodule Xandra.ClusterTest do
host: %Host{address: {198, 0, 0, 2}, port: @port, data_center: "local_dc"}
}

node1_address = "198.0.0.1:#{@port}"
node2_address = "198.0.0.2:#{@port}"

assert_receive {^test_ref, PoolMock, :init_called,
%{
pool_size: 1,
connection_options: %{nodes: ["198.0.0.1:9052"], cluster_pid: ^pid}
connection_options: %{nodes: [^node1_address], cluster_pid: ^pid}
}}

assert_receive {^test_ref, PoolMock, :init_called,
%{
pool_size: 1,
connection_options: %{nodes: ["198.0.0.2:9052"], cluster_pid: ^pid}
connection_options: %{nodes: [^node2_address], cluster_pid: ^pid}
}}

refute_receive {[:xandra, :cluster, :pool, :started], ^telemetry_ref, %{},
Expand Down
1 change: 1 addition & 0 deletions test/xandra_toxiproxy_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ defmodule XandraToxiproxyTest do

@moduletag :toxiproxy

@tag :cassandra_specific
test "execute/3,4 supports a network that slices packets",
%{start_options: opts, keyspace: keyspace} do
ToxiproxyEx.get!(:xandra_test_cassandra)
Expand Down

0 comments on commit 67f54b0

Please sign in to comment.