diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 195c6731..813da511 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -19,51 +19,55 @@ jobs: erlang: ['24.3'] steps: - - name: Cancel previous runs - uses: styfle/cancel-workflow-action@0.9.0 - with: - access_token: ${{ github.token }} - - name: Checkout Github repo - uses: actions/checkout@v2 - - name: Setup elixir & erlang enviroment - uses: actions/setup-elixir@v1 - with: - elixir-version: ${{matrix.elixir}} # Define the elixir version [required] - otp-version: ${{matrix.erlang}} # Define the OTP version [required] - experimental-otp: true # More info https://github.com/actions/setup-elixir/issues/31 - - name: Retrieve cached dependencies - uses: actions/cache@v2 - id: mix-cache - with: - path: | - deps - _build - key: ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-${{ hashFiles('mix.lock') }} - - name: Install dependencies - if: steps.mix-cache.outputs.cache-hit != 'true' - run: | - mix local.rebar --force - mix local.hex --force - mix deps.get - mix deps.compile + - name: Cancel previous runs + uses: styfle/cancel-workflow-action@0.9.0 + with: + access_token: ${{ github.token }} + - name: Checkout Github repo + uses: actions/checkout@v2 + - name: Setup elixir & erlang enviroment + uses: actions/setup-elixir@v1 + with: + elixir-version: ${{matrix.elixir}} # Define the elixir version [required] + otp-version: ${{matrix.erlang}} # Define the OTP version [required] + experimental-otp: true # More info https://github.com/actions/setup-elixir/issues/31 + + - name: Retrieve Mix Dependencies Cache + uses: actions/cache@v2 + id: mix-cache # id to use in retrieve action + with: + path: deps + key: ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-mix-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }} + + - name: Retrieve Mix Dependencies Compilation Cache + uses: actions/cache@v2 + id: mix-deps-compile-cache # id to use in retrieve action + with: + path: _build + key: ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-mix-deps-compile-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }} + - name: Install Mix Dependencies + if: steps.mix-cache.outputs.cache-hit != 'true' + run: | + mix local.rebar --force + mix local.hex --force + mix deps.get + + - name: Compile Mix Dependencies + if: steps.mix-deps-compile-cache.outputs.cache-hit != 'true' + run: mix deps.compile run-checks: name: check runs-on: ubuntu-20.04 - needs: [setup] + needs: [dependencies] env: MIX_ENV: dev strategy: fail-fast: false matrix: - include: - - elixir: 1.10.2 - erlang: 22.3 - checks: - - mix credo - - mix compile --warnings-as-errors --force - - mix format --check-formatted + elixir: ['1.12.3'] + erlang: ['24.3'] steps: - uses: actions/checkout@v2 @@ -88,20 +92,22 @@ jobs: path: _build key: ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-mix-deps-compile-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }} - - run: ${{ matrix.checks }} + - run: | + mix credo + mix compile --warnings-as-errors --force + mix format --check-formatted dialyzer: name: check / dialyzer - needs: [setup] + needs: [dependencies] runs-on: ubuntu-latest env: MIX_ENV: dev strategy: matrix: - include: - - elixir: 1.10.2 - erlang: 22.3 + elixir: ['1.12.3'] + erlang: ['24.3'] steps: - uses: actions/checkout@v2 diff --git a/docker-compose.yml b/docker-compose.yml index ef1682f5..42329210 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -69,13 +69,15 @@ services: - ./ssl/kafka.server.keystore.jks:/etc/kafka/secrets/kafka.server.keystore.jks:ro,z - ./ssl/kafka.server.truststore.jks:/etc/kafka/secrets/kafka.server.truststore.jks:ro,z - ready: - image: busybox:1.31-musl - command: tail -f /dev/null + kafka_setup: + image: confluentinc/cp-kafka:5.5.1 depends_on: kafka-1: condition: service_healthy kafka-2: condition: service_healthy kafka-3: - condition: service_healthy \ No newline at end of file + condition: service_healthy + command: "bash -c 'kafka-topics --zookeeper zookeeper:32181 --create --if-not-exists --partitions 4 --replication-factor 2 --topic consumer_group_implementation_test && \ + kafka-topics --zookeeper zookeeper:32181 --create --if-not-exists --partitions 4 --replication-factor 2 --topic test0p8p0 && \ + kafka-topics --zookeeper zookeeper:32181 --list'" diff --git a/test/integration/kayrock/compatibility_0_p_10_and_later_test.exs b/test/integration/kayrock/compatibility_0_p_10_and_later_test.exs index 5a696433..c69bd39d 100644 --- a/test/integration/kayrock/compatibility_0_p_10_and_later_test.exs +++ b/test/integration/kayrock/compatibility_0_p_10_and_later_test.exs @@ -65,40 +65,54 @@ defmodule KafkaEx.KayrockCompatibility0p10AndLaterTest do # note this checks against the version of broker we're running in test # api_key, max_version, min_version api_versions_kafka_0_11_0_1 = [ - [0, 3, 0], - [1, 5, 0], - [2, 2, 0], - [3, 4, 0], - [4, 0, 0], - [5, 0, 0], - [6, 3, 0], - [7, 1, 1], - [8, 3, 0], - [9, 3, 0], - [10, 1, 0], - [11, 2, 0], - [12, 1, 0], - [13, 1, 0], - [14, 1, 0], - [15, 1, 0], - [16, 1, 0], - [17, 0, 0], - [18, 1, 0], - [19, 2, 0], - [20, 1, 0], - [21, 0, 0], - [22, 0, 0], - [23, 0, 0], - [24, 0, 0], - [25, 0, 0], - [26, 0, 0], + [0, 8, 0], + [1, 11, 0], + [2, 5, 0], + [3, 9, 0], + [4, 4, 0], + [5, 2, 0], + [6, 6, 0], + [7, 3, 0], + [8, 8, 0], + [9, 7, 0], + [10, 3, 0], + [11, 7, 0], + [12, 4, 0], + [13, 4, 0], + [14, 5, 0], + [15, 5, 0], + [16, 3, 0], + [17, 1, 0], + [18, 3, 0], + [19, 5, 0], + [20, 4, 0], + [21, 1, 0], + [22, 3, 0], + [23, 3, 0], + [24, 1, 0], + [25, 1, 0], + [26, 1, 0], [27, 0, 0], - [28, 0, 0], - [29, 0, 0], - [30, 0, 0], - [31, 0, 0], - [32, 0, 0], - [33, 0, 0] + [28, 3, 0], + [29, 2, 0], + [30, 2, 0], + [31, 2, 0], + [32, 2, 0], + [33, 1, 0], + [34, 1, 0], + [35, 1, 0], + [36, 2, 0], + [37, 2, 0], + [38, 2, 0], + [39, 2, 0], + [40, 2, 0], + [41, 2, 0], + [42, 2, 0], + [43, 2, 0], + [44, 1, 0], + [45, 0, 0], + [46, 0, 0], + [47, 0, 0] ] response = KafkaEx.api_versions(worker_name: client) diff --git a/test/integration/server0_p_10_p_1_test.exs b/test/integration/server0_p_10_p_1_test.exs index 4285c9b5..fd78d507 100644 --- a/test/integration/server0_p_10_p_1_test.exs +++ b/test/integration/server0_p_10_p_1_test.exs @@ -11,40 +11,54 @@ defmodule KafkaEx.Server0P10P1.Test do # note this checks against the version of broker we're running in test # api_key, max_version, min_version api_versions_kafka_0_11_0_1 = [ - [0, 3, 0], - [1, 5, 0], - [2, 2, 0], - [3, 4, 0], - [4, 0, 0], - [5, 0, 0], - [6, 3, 0], - [7, 1, 1], - [8, 3, 0], - [9, 3, 0], - [10, 1, 0], - [11, 2, 0], - [12, 1, 0], - [13, 1, 0], - [14, 1, 0], - [15, 1, 0], - [16, 1, 0], - [17, 0, 0], - [18, 1, 0], - [19, 2, 0], - [20, 1, 0], - [21, 0, 0], - [22, 0, 0], - [23, 0, 0], - [24, 0, 0], - [25, 0, 0], - [26, 0, 0], + [0, 8, 0], + [1, 11, 0], + [2, 5, 0], + [3, 9, 0], + [4, 4, 0], + [5, 2, 0], + [6, 6, 0], + [7, 3, 0], + [8, 8, 0], + [9, 7, 0], + [10, 3, 0], + [11, 7, 0], + [12, 4, 0], + [13, 4, 0], + [14, 5, 0], + [15, 5, 0], + [16, 3, 0], + [17, 1, 0], + [18, 3, 0], + [19, 5, 0], + [20, 4, 0], + [21, 1, 0], + [22, 3, 0], + [23, 3, 0], + [24, 1, 0], + [25, 1, 0], + [26, 1, 0], [27, 0, 0], - [28, 0, 0], - [29, 0, 0], - [30, 0, 0], - [31, 0, 0], - [32, 0, 0], - [33, 0, 0] + [28, 3, 0], + [29, 2, 0], + [30, 2, 0], + [31, 2, 0], + [32, 2, 0], + [33, 1, 0], + [34, 1, 0], + [35, 1, 0], + [36, 2, 0], + [37, 2, 0], + [38, 2, 0], + [39, 2, 0], + [40, 2, 0], + [41, 2, 0], + [42, 2, 0], + [43, 2, 0], + [44, 1, 0], + [45, 0, 0], + [46, 0, 0], + [47, 0, 0] ] response = KafkaEx.api_versions() diff --git a/test/socket_test.exs b/test/socket_test.exs index 9a71fc20..47a69fe2 100644 --- a/test/socket_test.exs +++ b/test/socket_test.exs @@ -36,6 +36,7 @@ defmodule KafkaEx.Socket.Test do {:ok, listen_socket} = :ssl.listen(port, [ :binary, + {:verify, :verify_none}, {:active, false}, {:reuseaddr, true}, {:packet, 0}, @@ -49,7 +50,7 @@ defmodule KafkaEx.Socket.Test do defp listen(socket) do case :ssl.transport_accept(socket) do {:ok, conn} -> - :ok = :ssl.ssl_accept(conn) + {:ok, _socket} = :ssl.handshake(conn) pid = spawn_link(fn -> recv(conn) end) :ssl.controlling_process(socket, pid) @@ -73,92 +74,103 @@ defmodule KafkaEx.Socket.Test do setup_all do :ssl.start() - SSLServer.start(3030) - Server.start(3040) - {:ok, [ssl_port: 3030, port: 3040]} end - test "create a non SSL socket", context do - {:ok, socket} = - KafkaEx.Socket.create( - 'localhost', - context[:port], - [:binary, {:packet, 0}], - false - ) - - assert socket.ssl == false - KafkaEx.Socket.close(socket) - end + describe "without SSL socket" do + setup do + Server.start(3040) + {:ok, [port: 3040]} + end - test "send and receive using a non SSL socket", context do - {:ok, socket} = - KafkaEx.Socket.create( - 'localhost', - context[:port], - [:binary, {:packet, 0}, {:active, false}], - false - ) - - KafkaEx.Socket.send(socket, 'ping') - assert {:ok, "ping"} == KafkaEx.Socket.recv(socket, 0) - KafkaEx.Socket.close(socket) - end + test "create a non SSL socket", context do + {:ok, socket} = + KafkaEx.Socket.create( + 'localhost', + context[:port], + [:binary, {:packet, 0}], + false + ) + + assert socket.ssl == false + KafkaEx.Socket.close(socket) + end - test "retrieve info from a non SSL socket", context do - {:ok, socket} = - KafkaEx.Socket.create( - 'localhost', - context[:port], - [:binary, {:packet, 0}, {:active, false}], - false - ) - - info = KafkaEx.Socket.info(socket) - assert info[:name] == 'tcp_inet' - KafkaEx.Socket.close(socket) - assert {:error, :closed} == KafkaEx.Socket.send(socket, 'ping') - end + test "send and receive using a non SSL socket", context do + {:ok, socket} = + KafkaEx.Socket.create( + 'localhost', + context[:port], + [:binary, {:packet, 0}, {:active, false}], + false + ) + + KafkaEx.Socket.send(socket, 'ping') + assert {:ok, "ping"} == KafkaEx.Socket.recv(socket, 0) + KafkaEx.Socket.close(socket) + end - test "create a SSL socket", context do - {:ok, socket} = - KafkaEx.Socket.create( - 'localhost', - context[:ssl_port], - [:binary, {:packet, 0}], - true - ) - - assert socket.ssl == true - KafkaEx.Socket.close(socket) + test "retrieve info from a non SSL socket", context do + {:ok, socket} = + KafkaEx.Socket.create( + 'localhost', + context[:port], + [:binary, {:packet, 0}, {:active, false}], + false + ) + + info = KafkaEx.Socket.info(socket) + assert info[:name] == 'tcp_inet' + KafkaEx.Socket.close(socket) + assert {:error, :closed} == KafkaEx.Socket.send(socket, 'ping') + end end - test "send and receive using a SSL socket", context do - {:ok, socket} = - KafkaEx.Socket.create( - 'localhost', - context[:ssl_port], - [:binary, {:packet, 0}, {:active, false}], - true - ) - - KafkaEx.Socket.send(socket, 'ping') - assert {:ok, "ping"} == KafkaEx.Socket.recv(socket, 0) - KafkaEx.Socket.close(socket) - end + describe "with ssl socket" do + setup do + SSLServer.start(3030) + {:ok, [ssl_port: 3030]} + end + + test "create a SSL socket", context do + {:ok, socket} = + KafkaEx.Socket.create( + 'localhost', + context[:ssl_port], + [:binary, {:packet, 0}], + true + ) + + assert socket.ssl == true + KafkaEx.Socket.close(socket) + end - test "retrieve info from a SSL socket", context do - {:ok, socket} = - KafkaEx.Socket.create( - 'localhost', - context[:ssl_port], - [:binary, {:packet, 0}, {:active, false}], - true - ) - - info = KafkaEx.Socket.info(socket) - assert info[:name] == 'tcp_inet' - KafkaEx.Socket.close(socket) - assert {:error, :closed} == KafkaEx.Socket.send(socket, 'ping') + test "send and receive using a SSL socket", context do + {:ok, socket} = + KafkaEx.Socket.create( + 'localhost', + context[:ssl_port], + [:binary, {:packet, 0}, {:active, false}], + true + ) + + KafkaEx.Socket.send(socket, 'ping') + assert {:ok, "ping"} == KafkaEx.Socket.recv(socket, 0) + KafkaEx.Socket.close(socket) + end + + test "retrieve info from a SSL socket", context do + {:ok, socket} = + KafkaEx.Socket.create( + 'localhost', + context[:ssl_port], + [:binary, {:packet, 0}, {:active, false}], + true + ) + + info = KafkaEx.Socket.info(socket) + assert info[:name] == 'tcp_inet' + KafkaEx.Socket.close(socket) + assert {:error, :closed} == KafkaEx.Socket.send(socket, 'ping') + end end end