diff options
author | Lukasz Woznicki <lukasz.woznicki@softwareag.com> | 2022-02-09 15:34:28 +0000 |
---|---|---|
committer | Lukasz Woznicki <lukasz.woznicki@softwareag.com> | 2022-02-18 10:37:55 +0000 |
commit | a4623550c0e05c0e0746fa25a035244a0882e579 (patch) | |
tree | 40219860809ba1479ed1bcbbd4427b74edc6d93a /crates/tests | |
parent | 5bbe2e54ad664431f1b6f4514b470b46af9cd8c6 (diff) |
Move c8y mapper tests to c8y module and fix docs for tests.
Add convenience method to c8y mapper tests to wait until all messages are received
Remove unwraps from converter
Move code to functions in converter
Move tests from converter and FakeC8yProxy to tests
Update docs, remove extranous 'mapper'
Signed-off-by: Lukasz Woznicki <lukasz.woznicki@softwareag.com>
Add more informative notice to assert_received_all_expected
Mark all the tokio::test with multi_thread flavour
Signed-off-by: Lukasz Woznicki <lukasz.woznicki@softwareag.com>
Diffstat (limited to 'crates/tests')
-rw-r--r-- | crates/tests/mqtt_tests/src/lib.rs | 3 | ||||
-rw-r--r-- | crates/tests/mqtt_tests/src/test_mqtt_client.rs | 27 |
2 files changed, 28 insertions, 2 deletions
diff --git a/crates/tests/mqtt_tests/src/lib.rs b/crates/tests/mqtt_tests/src/lib.rs index 9144dd4e..c51498a9 100644 --- a/crates/tests/mqtt_tests/src/lib.rs +++ b/crates/tests/mqtt_tests/src/lib.rs @@ -5,6 +5,5 @@ pub mod with_timeout; pub use futures::{SinkExt, StreamExt}; pub use message_streams::*; -pub use test_mqtt_client::assert_received; -pub use test_mqtt_client::publish; +pub use test_mqtt_client::{assert_received, assert_received_all_expected, publish}; pub use test_mqtt_server::test_mqtt_broker; diff --git a/crates/tests/mqtt_tests/src/test_mqtt_client.rs b/crates/tests/mqtt_tests/src/test_mqtt_client.rs index c12047f6..d0a778d6 100644 --- a/crates/tests/mqtt_tests/src/test_mqtt_client.rs +++ b/crates/tests/mqtt_tests/src/test_mqtt_client.rs @@ -52,6 +52,33 @@ pub async fn assert_received<T>( } } +/// Push received `messages` until all messages containing `expected` strings have been received or until `timeout`. +pub async fn assert_received_all_expected<T>( + messages: &mut UnboundedReceiver<String>, + timeout: Duration, + expected: T, +) where + T: IntoIterator, + T::Item: ToString, +{ + let mut expected = expected + .into_iter() + .map(|s| s.to_string()) + .collect::<Vec<_>>(); + + while let Ok(Some(msg)) = messages.next().with_timeout(timeout).await { + expected.retain(|expected_msg| !msg.contains(expected_msg)); + if expected.is_empty() { + return; + } + } + + assert!( + expected.is_empty(), + "Didn't receive all expected messages: {expected:?}", + ); +} + /// Publish a message /// /// Return only when the message has been acknowledged. |