From 0cd7893e56304dd4b63893969993071dd3818518 Mon Sep 17 00:00:00 2001 From: Vladimir Kotal Date: Thu, 9 Jan 2025 11:55:37 +0100 Subject: [PATCH 1/2] add test for the PUBLISH+UNSUBACK case --- tests/test_unsubscribe.py | 45 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/tests/test_unsubscribe.py b/tests/test_unsubscribe.py index f7bbb21a..1dfbb856 100644 --- a/tests/test_unsubscribe.py +++ b/tests/test_unsubscribe.py @@ -68,6 +68,49 @@ def handle_unsubscribe(client, user_data, topic, pid): + [0x6F] * 257 ), ), + # UNSUBSCRIBE responded to by PUBLISH followed by UNSUBACK + ( + "foo/bar", + bytearray( + [ + 0x30, # PUBLISH + 0x0C, + 0x00, + 0x07, + 0x66, + 0x6F, + 0x6F, + 0x2F, + 0x62, + 0x61, + 0x72, + 0x66, + 0x6F, + 0x6F, + 0xB0, # UNSUBACK + 0x02, + 0x00, + 0x01, + ] + ), + bytearray( + [ + 0xA2, # fixed header + 0x0B, # remaining length + 0x00, + 0x01, # message ID + 0x00, + 0x07, # topic length + 0x66, # topic + 0x6F, + 0x6F, + 0x2F, + 0x62, + 0x61, + 0x72, + ] + ), + ), # use list of topics for more coverage. If the range was (1, 10000), that would be # long enough to use 3 bytes for remaining length, however that would make the test # run for many minutes even on modern systems, so 1000 is used instead. @@ -95,7 +138,7 @@ def handle_unsubscribe(client, user_data, topic, pid): @pytest.mark.parametrize( "topic,to_send,exp_recv", testdata, - ids=["short_topic", "long_topic", "topic_list_long"], + ids=["short_topic", "long_topic", "publish_first", "topic_list_long"], ) def test_unsubscribe(topic, to_send, exp_recv) -> None: """ From b8fa023c7e0d94be9f362fa8bdd71c7f11b50484 Mon Sep 17 00:00:00 2001 From: Vladimir Kotal Date: Sun, 19 Jan 2025 10:58:27 +0100 Subject: [PATCH 2/2] no need to check zero byte returned from recv_into() fixes #157 --- adafruit_minimqtt/adafruit_minimqtt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_minimqtt/adafruit_minimqtt.py b/adafruit_minimqtt/adafruit_minimqtt.py index b216b16e..75148ed4 100644 --- a/adafruit_minimqtt/adafruit_minimqtt.py +++ b/adafruit_minimqtt/adafruit_minimqtt.py @@ -1015,7 +1015,7 @@ def _wait_for_msg( # noqa: PLR0912, Too many branches return None raise MMQTTException from error - if res in [None, b"", b"\x00"]: + if res in [None, b""]: # If we get here, it means that there is nothing to be received return None pkt_type = res[0] & MQTT_PKT_TYPE_MASK