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

Enable Toxiproxy in CI #343

Closed
wants to merge 7 commits into from
Closed
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
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,11 @@ jobs:
# 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
run: mix test.all --exclude encryption

- name: Run tests for Cassandra only
if: ${{ matrix.test_only_cassandra }}
run: mix test --trace --exclude encryption --exclude toxiproxy
run: mix test --exclude encryption

- name: Dump Docker logs on failure
uses: jwalton/gh-docker-logs@v1
Expand Down
11 changes: 7 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ services:
dockerfile: cassandra.dockerfile
args:
CASSANDRA_VERSION: "${CASSANDRA_VERSION:-4.1}"
hostname: cassandra
expose:
- "9042"
ports:
- "9052:9042" # TCP connections
- "9152:9142" # TLS/SSL connections
Expand Down Expand Up @@ -91,10 +94,10 @@ services:

toxiproxy:
image: ghcr.io/shopify/toxiproxy:2.6.0
command: -config=/config/toxiproxy.json -host 0.0.0.0
volumes:
- ./test/toxiproxy_config.json:/config/toxiproxy.json
ports:
- "8474:8474"
- "19052:9042"
- "19152:9043"
depends_on:
- "cassandra"
links:
- "cassandra"
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ defmodule Xandra.Mixfile do
{:mox, "~> 1.0", only: :test},
{:stream_data, "~> 0.6.0", only: [:dev, :test]},
{:nimble_lz4, "~> 0.1.3", only: [:dev, :test]},
{:toxiproxy_ex, "~> 1.1", only: :test}
{:toxiproxy_ex, github: "whatyouhide/toxiproxy_ex", only: :test}
]
end
end
4 changes: 2 additions & 2 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
%{
"castore": {:hex, :castore, "1.0.3", "7130ba6d24c8424014194676d608cb989f62ef8039efd50ff4b3f33286d06db8", [:mix], [], "hexpm", "680ab01ef5d15b161ed6a95449fac5c6b8f60055677a8e79acf01b27baa4390b"},
"castore": {:hex, :castore, "1.0.4", "ff4d0fb2e6411c0479b1d965a814ea6d00e51eb2f58697446e9c41a97d940b28", [:mix], [], "hexpm", "9418c1b8144e11656f0be99943db4caf04612e3eaecefb5dae9a2a87565584f8"},
"decimal": {:hex, :decimal, "2.1.1", "5611dca5d4b2c3dd497dec8f68751f1f1a54755e8ed2a966c2633cf885973ad6", [:mix], [], "hexpm", "53cfe5f497ed0e7771ae1a475575603d77425099ba5faef9394932b35020ffcc"},
"dialyxir": {:hex, :dialyxir, "1.4.1", "a22ed1e7bd3a3e3f197b68d806ef66acb61ee8f57b3ac85fc5d57354c5482a93", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "84b795d6d7796297cca5a3118444b80c7d94f7ce247d49886e7c291e1ae49801"},
"earmark_parser": {:hex, :earmark_parser, "1.4.35", "437773ca9384edf69830e26e9e7b2e0d22d2596c4a6b17094a3b29f01ea65bb8", [:mix], [], "hexpm", "8652ba3cb85608d0d7aa2d21b45c6fad4ddc9a1f9a1f1b30ca3a246f0acc33f6"},
Expand All @@ -23,5 +23,5 @@
"telemetry": {:hex, :telemetry, "1.2.1", "68fdfe8d8f05a8428483a97d7aab2f268aaff24b49e0f599faa091f1d4e7f61c", [:rebar3], [], "hexpm", "dad9ce9d8effc621708f99eac538ef1cbe05d6a874dd741de2e689c47feafed5"},
"tesla": {:hex, :tesla, "1.7.0", "a62dda2f80d4f8a925eb7b8c5b78c461e0eb996672719fe1a63b26321a5f8b4e", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:exjsx, ">= 3.0.0", [hex: :exjsx, repo: "hexpm", optional: true]}, {:finch, "~> 0.13", [hex: :finch, repo: "hexpm", optional: true]}, {:fuse, "~> 2.4", [hex: :fuse, repo: "hexpm", optional: true]}, {:gun, "~> 1.3", [hex: :gun, repo: "hexpm", optional: true]}, {:hackney, "~> 1.6", [hex: :hackney, repo: "hexpm", optional: true]}, {:ibrowse, "4.4.0", [hex: :ibrowse, repo: "hexpm", optional: true]}, {:jason, ">= 1.0.0", [hex: :jason, repo: "hexpm", optional: true]}, {:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mint, "~> 1.0", [hex: :mint, repo: "hexpm", optional: true]}, {:msgpax, "~> 2.3", [hex: :msgpax, repo: "hexpm", optional: true]}, {:poison, ">= 1.0.0", [hex: :poison, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: true]}], "hexpm", "2e64f01ebfdb026209b47bc651a0e65203fcff4ae79c11efb73c4852b00dc313"},
"toml": {:hex, :toml, "0.7.0", "fbcd773caa937d0c7a02c301a1feea25612720ac3fa1ccb8bfd9d30d822911de", [:mix], [], "hexpm", "0690246a2478c1defd100b0c9b89b4ea280a22be9a7b313a8a058a2408a2fa70"},
"toxiproxy_ex": {:hex, :toxiproxy_ex, "1.1.1", "af605b9f54a4508e2c8987764301609f457076cafc472ba83beaec93e2796e99", [:mix], [{:castore, "~> 1.0.3", [hex: :castore, repo: "hexpm", optional: false]}, {:jason, ">= 1.0.0", [hex: :jason, repo: "hexpm", optional: false]}, {:mint, "~> 1.0", [hex: :mint, repo: "hexpm", optional: false]}, {:tesla, "~> 1.7.0", [hex: :tesla, repo: "hexpm", optional: false]}], "hexpm", "826c415c6e8ec1708894a86091afd0674f0a4115ed09ac6604088ef916226fe7"},
"toxiproxy_ex": {:git, "https://github.com/whatyouhide/toxiproxy_ex.git", "11dc70cbe223a8b57455d8eacbc80ec9ea7e89d7", []},
}
7 changes: 7 additions & 0 deletions test/test_helper.exs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,11 @@ excluded =

Mox.defmock(LBPMock, for: Xandra.Cluster.LoadBalancingPolicy)

{proxies, _} = Code.eval_file("test/toxiproxy_proxies.exs")
ToxiproxyEx.populate!(proxies)

ExUnit.after_suite(fn _result ->
ToxiproxyEx.reset!()
end)

ExUnit.start(exclude: excluded, assert_receive_timeout: 1_000)
14 changes: 0 additions & 14 deletions test/toxiproxy_config.json

This file was deleted.

8 changes: 8 additions & 0 deletions test/toxiproxy_proxies.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[
%{
name: "xandra_test_cassandra",
listen: "[::]:9042",
upstream: "cassandra:9042",
enabled: true
}
]
21 changes: 10 additions & 11 deletions test/xandra_toxiproxy_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@

@moduletag :toxiproxy

@toxic_proxy_node "localhost:19052"

setup %{start_options: opts} do
%{start_options: Keyword.merge(opts, nodes: [@toxic_proxy_node])}
end

test "execute/3,4 supports a network that slices packets",
%{start_options: opts, keyspace: keyspace} do
ToxiproxyEx.get!(:xandra_test_cassandra_sliced)
ToxiproxyEx.get!(:xandra_test_cassandra)
|> ToxiproxyEx.toxic(:slicer, average_size: 50, size_variation: 25, delay: _microsec = 50)
|> ToxiproxyEx.apply!(fn ->
opts = Keyword.merge(opts, nodes: ["127.0.0.1:19152"], keyspace: keyspace)
opts = Keyword.merge(opts, keyspace: keyspace)
conn = start_supervised!({Xandra, opts})
assert {:ok, prepared} = Xandra.prepare(conn, "SELECT * FROM system.local WHERE key = ?")
assert {:ok, page} = Xandra.execute(conn, prepared, ["local"])
Expand All @@ -20,7 +26,6 @@
end

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

ToxiproxyEx.get!(:xandra_test_cassandra)
Expand All @@ -30,25 +35,19 @@
end)
end

test "prepare/3 when the connection goes down mid request", %{start_options: opts} do

Check failure on line 38 in test/xandra_toxiproxy_test.exs

View workflow job for this annotation

GitHub Actions / Test (Elixir 1.15.4, OTP 25.3, C* , Scylla , Native protocol v5)

test prepare/3 when the connection goes down mid request (XandraToxiproxyTest)
opts = Keyword.merge(opts, nodes: ["127.0.0.1:19052"])
conn = start_supervised!({Xandra, opts})

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

test "start_link/1 supports the :connect_timeout option", %{start_options: opts} do

Check failure on line 49 in test/xandra_toxiproxy_test.exs

View workflow job for this annotation

GitHub Actions / Test (Elixir 1.15.4, OTP 25.3, C* 4.1, Scylla 5.1.6, Native protocol v3)

test start_link/1 supports the :connect_timeout option (XandraToxiproxyTest)

Check failure on line 49 in test/xandra_toxiproxy_test.exs

View workflow job for this annotation

GitHub Actions / Test (Elixir 1.15.4, OTP 25.3, C* 4.1, Scylla 5.1.6, Native protocol v4)

test start_link/1 supports the :connect_timeout option (XandraToxiproxyTest)

Check failure on line 49 in test/xandra_toxiproxy_test.exs

View workflow job for this annotation

GitHub Actions / Test (Elixir 1.15.4, OTP 25.3, C* , Scylla , Native protocol v5)

test start_link/1 supports the :connect_timeout option (XandraToxiproxyTest)
opts =
Keyword.merge(opts,
connect_timeout: 0,
backoff_type: :stop,
nodes: ["127.0.0.1:19052"]
)
opts = Keyword.merge(opts, connect_timeout: 0, backoff_type: :stop)

ToxiproxyEx.get!(:xandra_test_cassandra)
|> ToxiproxyEx.toxic(:timeout, timeout: 0)
Expand Down
Loading