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))) => { 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..a8aee9f82ac --- /dev/null +++ b/tests/RobotFramework/tests/cumulocity/bridge_config/builtin_bridge.robot @@ -0,0 +1,37 @@ +*** Settings *** +Resource ../../../resources/common.resource +Library Cumulocity +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 + + +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 + ${DEVICE_SN}= Setup + Set Suite Variable ${DEVICE_SN} + Execute Command tedge config set mqtt.bridge.built_in true + Execute Command tedge reconnect c8y