diff --git a/.github/workflows/elixir.yaml b/.github/workflows/elixir.yaml new file mode 100644 index 0000000..b0f0bd1 --- /dev/null +++ b/.github/workflows/elixir.yaml @@ -0,0 +1,81 @@ +name: CI Pipeline + +on: + pull_request: + push: + branches: ["main"] + +env: + MIX_ENV: test + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + +permissions: + contents: read + +jobs: + build: + name: Build and test + runs-on: ubuntu-20.04 + services: + mosquitto: + image: eclipse-mosquitto:2.0 + ports: + - "1883:1883" + - "1884:1884" + volumes: + - ${{ github.workspace }}/build/volume/.moquitto:/mosquitto/config + options: --name mqtt + strategy: + fail-fast: false + matrix: + include: + - elixir: "1.14" + otp: "23.0" + + # Latest versions. + - elixir: "1.17" + otp: "27.0" + lint: lint + coverage: coverage + steps: + - name: Check out this repository + uses: actions/checkout@v4 + + - name: Set up Erlang and Elixir + uses: erlef/setup-beam@v1 + with: + otp-version: ${{matrix.otp}} + elixir-version: ${{ matrix.elixir }} + + # Ensure to restart MQTT after checkout to correctly bind the config volume + - name: Restart MQTT + uses: docker://docker + with: + args: docker restart mqtt + + - name: Cache Mix dependencies + uses: actions/cache@v3 + id: cache-deps + with: + path: | + deps + _build + key: | + mix-${{ runner.os }}-${{matrix.elixir}}-${{matrix.otp}}-${{ hashFiles('**/mix.lock') }} + restore-keys: | + mix-${{ runner.os }}-${{matrix.elixir}}-${{matrix.otp}}- + + - run: mix do deps.get --check-locked, deps.compile + if: steps.cache-deps.outputs.cache-hit != 'true' + + - run: mix format --check-formatted + if: ${{ matrix.lint }} + + - run: mix deps.unlock --check-unused + if: ${{ matrix.lint }} + + - run: mix compile --warnings-as-errors + if: ${{ matrix.lint }} + + - run: mix coveralls.github + if: ${{ matrix.coverage }} diff --git a/test/off_broadway/emqtt/producer_test.exs b/test/off_broadway/emqtt/producer_test.exs index 14b1f16..c4af714 100644 --- a/test/off_broadway/emqtt/producer_test.exs +++ b/test/off_broadway/emqtt/producer_test.exs @@ -1,12 +1,11 @@ defmodule OffBroadway.EMQTT.ProducerTest do use ExUnit.Case, async: false - # import ExUnit.CaptureLog - @broadway_opts buffer_size: 10000, + @broadway_opts buffer_size: 10_000, buffer_overflow_strategy: :drop_head, config: [ - # host: "localhost", - host: "test.mosquitto.org", + host: "localhost", + # host: "test.mosquitto.org", port: 1884, username: "rw", password: "readwrite", @@ -90,7 +89,7 @@ defmodule OffBroadway.EMQTT.ProducerTest do ], batchers: [ default: [ - batch_size: 1000, + batch_size: 100, batch_timeout: 50, concurrency: 10 ] @@ -133,7 +132,7 @@ defmodule OffBroadway.EMQTT.ProducerTest do name = unique_name() {:ok, pid} = start_broadway(nil, name, @broadway_opts ++ [topics: [{"#", 0}]]) - Process.sleep(:timer.seconds(60)) + # Process.sleep(:timer.seconds(60)) stop_process(pid) end @@ -142,7 +141,6 @@ defmodule OffBroadway.EMQTT.ProducerTest do {:ok, message_server} = MessageServer.start_link() {:ok, pid} = start_broadway(message_server, name, @broadway_opts ++ [topics: [{"#", :at_least_once}]]) - IO.puts("Pushing messages") MessageServer.push_messages(message_server, "test", 1..5) Process.sleep(100)