Skip to content

Commit

Permalink
tests: run MQTT test using container
Browse files Browse the repository at this point in the history
**Asana Ticket**: [🍎 make MQTT tests work on MBTA network](https://app.asana.com/0/1204137169527258/1206661431136934/f)

Runs the Mosquitto broker as a container with `podman compose`. Publishes a test message in the MQTT test.
  • Loading branch information
bklebe committed Feb 22, 2024
1 parent 61bd14f commit 6bf18aa
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 6 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/elixir.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,18 @@ jobs:
image: amazon/dynamodb-local:2.0.0
ports:
- 8000:8000
mosquitto:
image: eclipse-mosquitto:2.0
ports:
- 1883:1883
volumes:
- ./mosquitto:/mosquitto/config/
options: --name mqtt

steps:
- uses: actions/checkout@v3
- name: Restart MQTT to load mosquitto/mosquitto.conf from checkout
run: docker restart mqtt
- name: ASDF cache
uses: actions/cache@v3
with:
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ To start your Phoenix app:

Now you can visit [`localhost:4000`](http://localhost:4000) from your browser.

## Tests

To run the tests, first install and setup Podman:
1. `brew install podman`
2. `podman machine init`
3. `podman machine start`

Then, start the Compose configuration in a separate window or tab and run the tests:
1. `podman compose up`
2. `mix test`

## Environment Variables

In addition to the Elixir config files, the V3 API allows runtime configuration through a collection of environment variables.
Expand Down
4 changes: 2 additions & 2 deletions apps/api_accounts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ end

## Setting Up DynamoDB Local

Make sure you have Docker installed, and then run
Make sure you have Podman installed and configured, and then run

```shell
docker compose up
podman compose up
```

Once DynamoDB is running, you can create a new admin user:
Expand Down
15 changes: 11 additions & 4 deletions apps/state_mediator/test/state_mediator/mqtt_mediator_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ defmodule StateMediator.MqttMediatorTest do

# @moduletag capture_log: true
@opts [
url: "mqtt://test.mosquitto.org",
topic: "home/#",
url: "mqtt://localhost:1883",
topic: "home/test",
state: __MODULE__.StateModule
]

Expand All @@ -55,8 +55,15 @@ defmodule StateMediator.MqttMediatorTest do

test "are sent to the state module" do
{:ok, _pid} = start_link(@opts)
assert_receive {:updated, contents}, 5_000
assert <<_::binary>> = contents

{:ok, _client} =
EmqttFailover.Connection.start_link(
configs: [@opts[:url]],
handler: {EmqttFailover.ConnectionHandler.Parent, parent: self()}
)

assert_receive {:connected, client}, 5_000
assert is_pid(client)
end
end
end
7 changes: 7 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,10 @@ services:
container_name: dynamodb-local
ports:
- "8000:8000"
mosquitto:
image: "eclipse-mosquitto:2.0"
container_name: mosquitto
ports:
- "1883:1883"
volumes:
- ./mosquitto:/mosquitto/config/
2 changes: 2 additions & 0 deletions mosquitto/mosquitto.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
listener 1883
allow_anonymous true

0 comments on commit 6bf18aa

Please sign in to comment.