From 61b5285cff16cd4665a53f7d25d20c43a70e64f5 Mon Sep 17 00:00:00 2001 From: David Cermak Date: Fri, 13 May 2022 10:48:28 +0200 Subject: [PATCH 1/2] mqtt: Fix incorrect reads on error (idf_v4.x) * Update submodule: git log --oneline 985078affa8a2d2b56b87c8e6455252850f895c6..27eb4726067465c5c67d4ecdca5ddccd26f02580 Detailed description of the changes: * MQTT: Fix signature matching for integer values (Backport to idf_v4.x) - See merge request espressif/esp-mqtt!133 - Closes https://github.com/espressif/esp-idf/issues/8482 - MQTT: Fix signature matching for integer values (espressif/esp-mqtt@f162002) * ci: Deploy idf_v4.x branch to GitHub (espressif/esp-mqtt@ee5ecad) --- components/mqtt/esp-mqtt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/mqtt/esp-mqtt b/components/mqtt/esp-mqtt index 985078affa..27eb472606 160000 --- a/components/mqtt/esp-mqtt +++ b/components/mqtt/esp-mqtt @@ -1 +1 @@ -Subproject commit 985078affa8a2d2b56b87c8e6455252850f895c6 +Subproject commit 27eb4726067465c5c67d4ecdca5ddccd26f02580 From 7691b44ee51dfa162ce7502266c6882f5809150f Mon Sep 17 00:00:00 2001 From: David Cermak Date: Wed, 26 Jan 2022 16:38:31 +0100 Subject: [PATCH 2/2] ci/mqtt: Fix weekend test publish-connect on target * Fix thread safe issue in paho-mqtt library * Move the weekend test to ethernet runner --- .gitlab/ci/target-test.yml | 2 +- .../mqtt/publish_connect_test/app_test.py | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/.gitlab/ci/target-test.yml b/.gitlab/ci/target-test.yml index eecba965b0..2bb6799ebd 100644 --- a/.gitlab/ci/target-test.yml +++ b/.gitlab/ci/target-test.yml @@ -57,7 +57,7 @@ test_weekend_mqtt: - .rules:labels:weekend_test tags: - ESP32 - - Example_WIFI + - Example_EthKitV1 script: - export MQTT_PUBLISH_TEST=1 - export TEST_PATH=$CI_PROJECT_DIR/tools/test_apps/protocols/mqtt/publish_connect_test diff --git a/tools/test_apps/protocols/mqtt/publish_connect_test/app_test.py b/tools/test_apps/protocols/mqtt/publish_connect_test/app_test.py index bb4e9dc5d0..cf4c612719 100644 --- a/tools/test_apps/protocols/mqtt/publish_connect_test/app_test.py +++ b/tools/test_apps/protocols/mqtt/publish_connect_test/app_test.py @@ -9,7 +9,8 @@ import ssl import string import subprocess import sys -from threading import Event, Thread +import time +from threading import Event, Lock, Thread import paho.mqtt.client as mqtt import ttfw_idf @@ -59,6 +60,7 @@ class MqttPublisher: self.publish_cfg['qos'] = qos self.publish_cfg['queue'] = queue self.publish_cfg['transport'] = transport + self.lock = Lock() # static variables used to pass options to and from static callbacks of paho-mqtt client MqttPublisher.event_client_connected = Event() MqttPublisher.event_client_got_all = Event() @@ -71,9 +73,11 @@ class MqttPublisher: if self.log_details: print(text) - def mqtt_client_task(self, client): + def mqtt_client_task(self, client, lock): while not self.event_stop_client.is_set(): - client.loop() + with lock: + client.loop() + time.sleep(0.001) # yield to other threads # The callback for when the client receives a CONNACK response from the server (needs to be static) @staticmethod @@ -120,18 +124,20 @@ class MqttPublisher: self.print_details('ENV_TEST_FAILURE: Unexpected error while connecting to broker {}'.format(broker_host)) raise # Starting a py-client in a separate thread - thread1 = Thread(target=self.mqtt_client_task, args=(self.client,)) + thread1 = Thread(target=self.mqtt_client_task, args=(self.client, self.lock)) thread1.start() self.print_details('Connecting py-client to broker {}:{}...'.format(broker_host, broker_port)) if not MqttPublisher.event_client_connected.wait(timeout=30): raise ValueError('ENV_TEST_FAILURE: Test script cannot connect to broker: {}'.format(broker_host)) - self.client.subscribe(self.publish_cfg['subscribe_topic'], qos) + with self.lock: + self.client.subscribe(self.publish_cfg['subscribe_topic'], qos) self.dut.write(' '.join(str(x) for x in (transport, self.sample_string, self.repeat, MqttPublisher.published, qos, queue)), eol='\n') try: # waiting till subscribed to defined topic self.dut.expect(re.compile(r'MQTT_EVENT_SUBSCRIBED'), timeout=30) for _ in range(MqttPublisher.published): - self.client.publish(self.publish_cfg['publish_topic'], self.sample_string * self.repeat, qos) + with self.lock: + self.client.publish(self.publish_cfg['publish_topic'], self.sample_string * self.repeat, qos) self.print_details('Publishing...') self.print_details('Checking esp-client received msg published from py-client...') self.dut.expect(re.compile(r'Correct pattern received exactly x times'), timeout=60)