Test mqqt behaviors and events emitted

I need to test mqqt behaviors and events emitted by mqtt. E.g whenever I(mock device) publish to mqtt, the Handler gets called by it with valid params(tested this with iex but needs to automate the process) and I performs some actions on the data.

Steps:

  1. installed mqqt via docker container
  2. added tortoise dependency to my elixir project
  3. and added basic listner
  4. and tried in console and listen successfully
Tortoise.publish(:client_id, "d", "my msg" , qos: 0).

Note: I tried to use mock and mox libraries for listening but unable to capture the call event

Question/issue: Mqtt listens to events(some device publish events to mqqt server) and Mqtt calls an elixir listener associated with it. I need to test this behavior: Lets say listener get called by mqqt within 10 seconds. How do I check inside test cases that this method/listener has been called within 10 seconds(with correct params) after I initiate a publish to mqqt

Library: https://github.com/gausby/tortoise

1 Like