Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MQTT metric unit tests part two #64

Merged
merged 44 commits into from
Nov 23, 2023
Merged

Conversation

ximon18
Copy link
Member

@ximon18 ximon18 commented Nov 20, 2023

This PR builds on and fixes some issues with PR #60.

Primary change:

  • As the event loop is not movable across threads/tasks it and the client must be created in the event loop task and the client passed out for use by the parent code.

Additionally:

  • Use the concept of "active" MQTT connection rather than "connected" as reconnection is handled transparently by the rumqttc event loop.
  • Introduce "mock poll result" support for testing with particular good/bad output froms the MQTT event poll()ing fn.
  • Count connection errors detected in the MQTT event loop.
  • Fix the connection_refused() test using the new "mock poll result" and connection error counting functionality.
  • Support dynamic reconfiguration (but currently not gracefully, unsent messages in the rumqttc internal queue will be dropped).
  • Fix the in-flight metric to use the rumqttc internal in-flight queue size.
  • Only terminate the rumqttc event loop on dynamic reconfiguration, allow it to persist during connection retry delays in order to send rumqttc internally queued messages on successful reconnection rather than lose them.
  • Add more unit tests.

…ough refactoring of the MQTT target into separate modules, replacing the use of separate Tokio tasks and multiple uses of select with a single tokio::select! macro, and splitting connection state handling into a dedicated type.
…pl for select Either, replaced by use of tokio::select! instead.
…in MQTT connection processing loop out of the `run()` fn into new fn `do_run()` for better testability.
…and a connection refused test that tests the connection established/lost metrics showing that the new testability works.
… cancel safe but a task JoinHandle is.

As the event loop is not movable across threads/tasks it and the client must be created in the event loop task and the client passed out for use by the parent code.

Additional changes:
- Use the concept of "active" MQTT connection rather than "conncted" as reconnection is handled transparently by the rumqttc event loop and thus we do not currently know if we are actually "connected" or not.
- Introduce "mock poll result" suport for testing with particular good/bad output froms the MQTT event `poll()`ing fn.
- Count connection errors detected in the MQTT event loop.- Fix the `connection_refused()` test using the new "mock poll result" and connection error counting functionality.
@ximon18 ximon18 changed the title MQTT metric unit tests 2 MQTT metric unit tests part two Nov 20, 2023
@ximon18 ximon18 marked this pull request as ready for review November 22, 2023 23:58
@ximon18 ximon18 changed the base branch from mqtt-metric-unit-tests to blocks-wip November 23, 2023 12:57
@ximon18 ximon18 merged commit d93a971 into blocks-wip Nov 23, 2023
1 check passed
@ximon18 ximon18 deleted the mqtt-metric-unit-tests-2 branch November 23, 2023 21:38
density215 pushed a commit that referenced this pull request Dec 8, 2023
This PR builds on and fixes some issues with PR #60.

Primary change:
- As the event loop is not movable across threads/tasks it and the client must be created in the event loop task and the client passed out for use by the parent code.

Additionally:
- Use the concept of "active" MQTT connection rather than "connected" as reconnection is handled transparently by the rumqttc event loop.
- Introduce "mock poll result" support for testing with particular good/bad output froms the MQTT event `poll()`ing fn.
- Count connection errors detected in the MQTT event loop.
- Fix the `connection_refused()` test using the new "mock poll result" and connection error counting functionality.
- Support dynamic reconfiguration (but currently not gracefully, unsent messages in the `rumqttc` internal queue will be dropped).
- Fix the in-flight metric to use the `rumqttc` internal in-flight queue size.
- Only terminate the `rumqttc` event loop on dynamic reconfiguration, allow it to persist during connection retry delays in order to send `rumqttc` internally queued messages on successful reconnection rather than lose them.
- Add more unit tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants