diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index dc9ba728..b52163ee 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 diff --git a/docker-compose.yml b/docker-compose.yml index c0296cbb..fa30b8e1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 @@ -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" diff --git a/mix.exs b/mix.exs index 913bcf82..5f20b742 100644 --- a/mix.exs +++ b/mix.exs @@ -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 diff --git a/mix.lock b/mix.lock index aa97cec0..50f6c7c8 100644 --- a/mix.lock +++ b/mix.lock @@ -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"}, @@ -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", []}, } diff --git a/test/test_helper.exs b/test/test_helper.exs index 4030bc85..de8a9701 100644 --- a/test/test_helper.exs +++ b/test/test_helper.exs @@ -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) diff --git a/test/toxiproxy_config.json b/test/toxiproxy_config.json deleted file mode 100644 index 2de037fe..00000000 --- a/test/toxiproxy_config.json +++ /dev/null @@ -1,14 +0,0 @@ -[ - { - "name": "xandra_test_cassandra", - "listen": "[::]:9042", - "upstream": "cassandra:9042", - "enabled": true - }, - { - "name": "xandra_test_cassandra_sliced", - "listen": "[::]:9043", - "upstream": "cassandra:9042", - "enabled": true - } -] diff --git a/test/toxiproxy_proxies.exs b/test/toxiproxy_proxies.exs new file mode 100644 index 00000000..b9a71148 --- /dev/null +++ b/test/toxiproxy_proxies.exs @@ -0,0 +1,8 @@ +[ + %{ + name: "xandra_test_cassandra", + listen: "[::]:9042", + upstream: "cassandra:9042", + enabled: true + } +] diff --git a/test/xandra_toxiproxy_test.exs b/test/xandra_toxiproxy_test.exs index aedd5780..3ef4c15d 100644 --- a/test/xandra_toxiproxy_test.exs +++ b/test/xandra_toxiproxy_test.exs @@ -6,12 +6,18 @@ defmodule XandraToxiproxyTest do @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"]) @@ -20,7 +26,6 @@ defmodule XandraToxiproxyTest do 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) @@ -31,11 +36,10 @@ defmodule XandraToxiproxyTest do end test "prepare/3 when the connection goes down mid request", %{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(: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") @@ -43,12 +47,7 @@ defmodule XandraToxiproxyTest do end test "start_link/1 supports the :connect_timeout option", %{start_options: opts} do - 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)