From e790772f6a4cfa97741ec002eb6cda544ce57f1e Mon Sep 17 00:00:00 2001 From: Reuben Miller Date: Wed, 31 Jul 2024 10:08:59 +0200 Subject: [PATCH 1/3] add system test for connection test using built-in bridge Signed-off-by: Reuben Miller --- .../bridge_config/builtin_bridge.robot | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 tests/RobotFramework/tests/cumulocity/bridge_config/builtin_bridge.robot diff --git a/tests/RobotFramework/tests/cumulocity/bridge_config/builtin_bridge.robot b/tests/RobotFramework/tests/cumulocity/bridge_config/builtin_bridge.robot new file mode 100644 index 00000000000..0fac5334489 --- /dev/null +++ b/tests/RobotFramework/tests/cumulocity/bridge_config/builtin_bridge.robot @@ -0,0 +1,24 @@ +*** Settings *** +Resource ../../../resources/common.resource +Library ThinEdgeIO + +Test Setup Custom Setup +Test Teardown Get Logs + +*** Test Cases *** + +Connection test + [Documentation] Repeatedly test the cloud connection + FOR ${attempt} IN RANGE 0 10 1 + ${output}= Execute Command tedge connect c8y --test timeout=10 + Should Not Contain ${output} connection check failed + END + + +*** Keywords *** + +Custom Setup + ${DEVICE_SN}= Setup + Set Suite Variable ${DEVICE_SN} + Execute Command tedge config set mqtt.bridge.built_in true + Execute Command tedge reconnect c8y From fcaafacb5b465145b4c84df5e91488c5a16a07b2 Mon Sep 17 00:00:00 2001 From: Reuben Miller Date: Wed, 31 Jul 2024 10:09:39 +0200 Subject: [PATCH 2/3] fix handling of messages with packet id 0 Messages with packet id 0 should be handled differently as they won't receive a PubAck or PubRec control messages hence it will never be removed from the hashmap and future messages with packet id 0 are ignored Signed-off-by: Reuben Miller --- crates/extensions/tedge_mqtt_bridge/src/lib.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/crates/extensions/tedge_mqtt_bridge/src/lib.rs b/crates/extensions/tedge_mqtt_bridge/src/lib.rs index 20e5e81381e..a19fd854845 100644 --- a/crates/extensions/tedge_mqtt_bridge/src/lib.rs +++ b/crates/extensions/tedge_mqtt_bridge/src/lib.rs @@ -377,7 +377,23 @@ async fn half_bridge( // Keep track of packet IDs so we can acknowledge messages Event::Outgoing(Outgoing::Publish(pkid)) => { - if let hash_map::Entry::Vacant(e) = forward_pkid_to_received_msg.entry(pkid) { + if pkid == 0 { + // Messages with pkid 0 (meaning QoS=0) should not be added to the hashmap + // as multiple messages with the pkid=0 can be received + match companion_bridge_half.recv().await { + // A message was forwarded by the other bridge half, note the packet id + Some(Some((topic, msg))) => { + loop_breaker.forward_on_topic(topic, &msg); + } + + // A healthcheck message was published, ignore this packet id + Some(None) => {} + + // The other bridge half has disconnected, break the loop and shut down the bridge + None => break, + } + } else if let hash_map::Entry::Vacant(e) = forward_pkid_to_received_msg.entry(pkid) + { match companion_bridge_half.recv().await { // A message was forwarded by the other bridge half, note the packet id Some(Some((topic, msg))) => { From bf9ed5087346c7526a0d1576ba3c2b94314f3a7a Mon Sep 17 00:00:00 2001 From: Reuben Miller Date: Wed, 31 Jul 2024 15:29:25 +0200 Subject: [PATCH 3/3] add system test explicit qos message published to c8y topic Signed-off-by: Reuben Miller --- .../cumulocity/bridge_config/builtin_bridge.robot | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/RobotFramework/tests/cumulocity/bridge_config/builtin_bridge.robot b/tests/RobotFramework/tests/cumulocity/bridge_config/builtin_bridge.robot index 0fac5334489..a8aee9f82ac 100644 --- a/tests/RobotFramework/tests/cumulocity/bridge_config/builtin_bridge.robot +++ b/tests/RobotFramework/tests/cumulocity/bridge_config/builtin_bridge.robot @@ -1,5 +1,6 @@ *** Settings *** Resource ../../../resources/common.resource +Library Cumulocity Library ThinEdgeIO Test Setup Custom Setup @@ -15,6 +16,18 @@ Connection test END +Support publishing QoS 0 messages to c8y topic #2960 + [Documentation] Verify the publishing of multiple QoS 0 message directly to the cloud connection + ... Note 1: Since QoS 0 aren't guarenteed to be delivered, use a non-strict assertion on the exact event count in the cloud. + ... During testing the test would reliably fail if the expected count is less than 10 messages. + ... Note 2: The bridge will automatically change the QoS from 0 when translating messages from te/# to c8y/#, + ... we can't use the te/# topics in the test. + FOR ${attempt} IN RANGE 0 20 1 + Execute Command tedge mqtt pub -q 0 c8y/s/us '400,test_q0,Test event with qos 0 attempt ${attempt}' timeout=10 + END + Cumulocity.Device Should Have Event/s expected_text=Test event with qos 0.* type=test_q0 minimum=10 + + *** Keywords *** Custom Setup