ci(mqtt): use QoS=1 for control messages in SSL test

SSL test relies on the device receiving a control message during the test, which was being sent
with QoS=0. Send the control message with QoS=1 to avoid failures due to poor network connection.
This commit is contained in:
Bogdan Kolendovskyy
2026-02-03 13:05:26 +01:00
committed by Euripedes Rocha
parent b6120b62d3
commit 7518cae20f
2 changed files with 30 additions and 8 deletions
+5 -2
View File
@@ -46,7 +46,7 @@ static void send_binary(esp_mqtt_client_handle_t client)
esp_partition_mmap(partition, 0, partition->size, ESP_PARTITION_MMAP_DATA, &binary_address, &out_handle);
// sending only the configured portion of the partition (if it's less than the partition size)
int binary_size = MIN(CONFIG_BROKER_BIN_SIZE_TO_SEND, partition->size);
int msg_id = esp_mqtt_client_publish(client, "/topic/binary", binary_address, binary_size, 0, 0);
int msg_id = esp_mqtt_client_publish(client, "/topic/binary", binary_address, binary_size, 1, 0);
ESP_LOGI(TAG, "binary sent with msg_id=%d", msg_id);
}
@@ -69,6 +69,8 @@ static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_
switch ((esp_mqtt_event_id_t)event_id) {
case MQTT_EVENT_CONNECTED:
ESP_LOGI(TAG, "MQTT_EVENT_CONNECTED");
esp_mqtt_client_subscribe(client, "/topic/binary", 1);
msg_id = esp_mqtt_client_subscribe(client, "/topic/qos0", 0);
ESP_LOGI(TAG, "sent subscribe successful, msg_id=%d", msg_id);
@@ -126,7 +128,8 @@ static void mqtt_app_start(void)
const esp_mqtt_client_config_t mqtt_cfg = {
.broker = {
.address.uri = CONFIG_BROKER_URI,
.verification.certificate = (const char *)mqtt_eclipseprojects_io_pem_start
.verification.certificate = (const char *)mqtt_eclipseprojects_io_pem_start,
.verification.skip_cert_common_name_check = true
},
};
+25 -6
View File
@@ -16,6 +16,7 @@ from pytest_embedded_idf.utils import idf_parametrize
event_client_connected = Event()
event_stop_client = Event()
event_client_connected_to_topic_binary = Event()
event_client_received_correct = Event()
event_client_received_binary = Event()
message_log = ''
@@ -37,14 +38,15 @@ def mqtt_client_task(client): # type: (mqtt.Client) -> None
# The callback for when a PUBLISH message is received from the server.
def on_message(client, userdata, msg): # type: (mqtt.Client, tuple, mqtt.client.MQTTMessage) -> None
global message_log
global event_client_connected_to_topic_binary
global event_client_received_correct
global event_client_received_binary
if msg.topic == '/topic/binary':
binary, bin_size = userdata
print('Receiving binary from esp and comparing with {}, size {}...'.format(binary, bin_size))
with open(binary, 'rb') as f:
bin = f.read()
if bin[:bin_size] == msg.payload[:bin_size]:
binary_reference = f.read()
if binary_reference[:bin_size] == msg.payload[:bin_size]:
print('...matches!')
event_client_received_binary.set()
return
@@ -56,9 +58,13 @@ def on_message(client, userdata, msg): # type: (mqtt.Client, tuple, mqtt.client
)
payload = msg.payload.decode()
if not event_client_received_correct.is_set() and payload == 'data':
client.subscribe('/topic/binary')
client.publish('/topic/qos0', 'send binary please')
if (
event_client_connected_to_topic_binary.is_set()
and not event_client_received_correct.is_set()
and payload == 'data'
):
client.publish('/topic/binary', 'send binary please', qos=1)
client.subscribe('/topic/binary', qos=1)
if msg.topic == '/topic/qos0' and payload == 'data':
event_client_received_correct.set()
message_log += 'Received data:' + msg.topic + ' ' + payload + '\n'
@@ -66,7 +72,7 @@ def on_message(client, userdata, msg): # type: (mqtt.Client, tuple, mqtt.client
@pytest.mark.ethernet
@idf_parametrize('target', ['esp32'], indirect=['target'])
def test_examples_protocol_mqtt_ssl(dut): # type: (Dut) -> None
def test_examples_protocol_mqtt_ssl(dut: Dut) -> None:
broker_url = ''
broker_port = 0
"""
@@ -122,6 +128,19 @@ def test_examples_protocol_mqtt_ssl(dut): # type: (Dut) -> None
except pexpect.TIMEOUT:
print('ENV_TEST_FAILURE: Cannot connect to AP')
raise
try:
dut.expect(r'MQTT_EVENT_CONNECTED', timeout=120)
# SSL example subscribes to topics /topic/binary, /topic/qos0, and /topic/qos1
# We do not want to introduce any logs related to /topic/binary, so we will
# wait for all three MQTT_EVENT_SUBSCRIBED to be processed
for i in range(3):
dut.expect(r'MQTT_EVENT_SUBSCRIBED, msg_id=(\d+)')
event_client_connected_to_topic_binary.set()
except pexpect.TIMEOUT:
print('ENV_TEST_FAILURE: Client cannot connect to the broker {}:{}.'.format(broker_url, broker_port))
raise
print('Checking py-client received msg published from esp...')
if not event_client_received_correct.wait(timeout=30):
raise ValueError('Wrong data received, msg log: {}'.format(message_log))