Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add overall coverage on CI #347

Merged
merged 7 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 15 additions & 21 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:

steps:
- name: Clone the repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install OTP and Elixir
uses: erlef/setup-beam@v1
Expand Down Expand Up @@ -78,8 +78,7 @@ jobs:
Test (Elixir ${{ matrix.elixir }},
OTP ${{ matrix.otp }},
C* ${{ matrix.server_versions.cassandra }},
Scylla ${{ matrix.server_versions.scylla }},
Native protocol ${{ matrix.cassandra_native_protocol }})
Scylla ${{ matrix.server_versions.scylla }} (coverage: ${{ matrix.coverage }})

runs-on: ubuntu-20.04

Expand All @@ -92,30 +91,25 @@ jobs:
elixir:
- "1.15.4"
server_versions:
- cassandra: "4.1"
scylla: "5.1.6"
- cassandra: "3"
scylla: "4.6.3"
cassandra_native_protocol:
- "v3"
- "v4"
include:
# Only C* 4.1+ supports native protocol v5.
- otp: "25.3"
elixir: "1.15.4"
test_only_cassandra: true
cassandra_version: "4.1"
cassandra_native_protocol: "v5"
coverage: true
server_versions:
cassandra: "4.1"
scylla: "5.2"


env:
CASSANDRA_VERSION: ${{ matrix.server_versions.cassandra }}
SCYLLA_VERSION: ${{ matrix.server_versions.scylla }}
CASSANDRA_NATIVE_PROTOCOL: ${{ matrix.cassandra_native_protocol }}
LOG_LEVEL: debug

steps:
- name: Clone the repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Start Docker and wait for it to be up
run: |
Expand All @@ -142,16 +136,16 @@ jobs:

- name: Install and compile dependencies
if: steps.cache-deps.outputs.cache-hit != 'true'
run: mix do deps.get --only test, deps.compile
run: mix do deps.get --only test + deps.compile

# TODO: eventually figure out why we can't run encryption tests on CI.
- name: Run tests for Cassandra and Scylla
if: ${{ !matrix.test_only_cassandra }}
run: mix test.all --trace --exclude encryption --exclude toxiproxy
- name: Run tests for Cassandra and Scylla (with coverage)
if: ${{ matrix.coverage }}
run: mix test.ci_with_coverage --exclude encryption --exclude toxiproxy

- name: Run tests for Cassandra only
if: ${{ matrix.test_only_cassandra }}
run: mix test --trace --exclude encryption --exclude toxiproxy
- name: Run tests for Cassandra and Scylla (without coverage)
if: ${{ !matrix.coverage }}
run: mix test.all --exclude encryption --exclude toxiproxy

- name: Dump Docker logs on failure
uses: jwalton/gh-docker-logs@v1
Expand Down
92 changes: 55 additions & 37 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ defmodule Xandra.Mixfile do
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
Expand Down Expand Up @@ -75,49 +74,68 @@ defmodule Xandra.Mixfile do
]
end

defp run_cassandra_tests(args, extra_env \\ []) do
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"}
] ++ extra_env
)
end

defp run_scylladb_tests(args, extra_env \\ []) do
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"}
] ++ extra_env
)
end

defp run_tests_with_protocols_and_coverage(coverage_task, args) do
for protocol <- ["", "v5", "v4", "v3"] do
run_cassandra_tests(
["--cover", "--export-coverage", "cassandra-#{protocol}" | args],
[{"CASSANDRA_NATIVE_PROTOCOL", to_string(protocol)}]
)
end

for protocol <- ["", "v4", "v3"] do
run_scylladb_tests(
["--cover", "--export-coverage", "scylladb-#{protocol}" | args],
[{"CASSANDRA_NATIVE_PROTOCOL", to_string(protocol)}]
)
end

Mix.Task.run(coverage_task, ["--exclude", "test", "--import-cover", "cover"])
end

defp aliases() do
[
test: "test --exclude 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.cassandra": &run_cassandra_tests/1,
"test.scylladb": &run_scylladb_tests/1,
"test.all": fn 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,
"test.all_with_html_coverage": &run_tests_with_protocols_and_coverage("coveralls.html", &1),
"test.ci_with_coverage": &run_tests_with_protocols_and_coverage("coveralls.github", &1),
docs: [
"run pages/generate_telemetry_events_page.exs",
"docs"
Expand Down
58 changes: 0 additions & 58 deletions test/support/mix_tasks/test.native_protocols.ex

This file was deleted.

9 changes: 0 additions & 9 deletions test/xandra_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,6 @@ defmodule XandraTest do
end
end

describe "prepare/3" do
test "supports the :timeout option", %{conn: conn} do
assert {:error, %ConnectionError{} = error} =
Xandra.prepare(conn, "SELECT * FROM system.local", timeout: 0)

assert error.reason == :timeout
end
end

describe "failure handling" do
test "reconnects if the connection drops", %{start_options: start_options} do
telemetry_ref =
Expand Down
14 changes: 14 additions & 0 deletions test/xandra_toxiproxy_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@ defmodule XandraToxiproxyTest do
end)
end

test "prepare/3 supports the :timeout option", %{start_options: opts} do
opts = Keyword.merge(opts, nodes: ["127.0.0.1:19052"])
conn = start_supervised!({Xandra, opts})

ToxiproxyEx.get!(:xandra_test_cassandra)
|> ToxiproxyEx.toxic(:timeout, timeout: 100)
|> ToxiproxyEx.apply!(fn ->
assert {:error, %ConnectionError{} = error} =
Xandra.prepare(conn, "SELECT * FROM system.local", timeout: 0)

assert error.reason == :timeout
end)
end

test "start_link/1 supports the :connect_timeout option", %{start_options: opts} do
opts =
Keyword.merge(opts,
Expand Down