Skip to content

Commit ba611c5

Browse files
committed
Add test for MQTTv5 connection to MQTTv3 broker
1 parent 50b280c commit ba611c5

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

tests/test_client.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import paho.mqtt.client as client
55
import pytest
6+
from paho.mqtt.reasoncodes import ReasonCodes
67

78
import tests.paho_test as paho_test
89

@@ -92,6 +93,50 @@ def on_connect(mqttc, obj, flags, rc):
9293
mqttc.loop_stop()
9394

9495

96+
class Test_connect_v5:
97+
"""
98+
Tests on connect/disconnect behaviour of the client with MQTTv5
99+
"""
100+
101+
def test_01_broker_no_support(self, fake_broker):
102+
mqttc = client.Client(
103+
"01-broker-no-support", protocol=client.MQTTv5)
104+
105+
def on_connect(mqttc, obj, flags, reason, properties):
106+
assert reason == 132
107+
assert reason == ReasonCodes(client.CONNACK >> 4, aName="Unsupported protocol version")
108+
mqttc.disconnect()
109+
110+
mqttc.on_connect = on_connect
111+
112+
mqttc.connect_async("localhost", fake_broker.port)
113+
mqttc.loop_start()
114+
115+
try:
116+
fake_broker.start()
117+
118+
# Can't test the connect_packet, we can't yet generate MQTTv5 packet.
119+
# connect_packet = paho_test.gen_connect(
120+
# "01-con-discon-success", keepalive=60,
121+
# proto_ver=client.MQTTv311)
122+
packet_in = fake_broker.receive_packet(1000)
123+
assert packet_in # Check connection was not closed
124+
# assert packet_in == connect_packet
125+
126+
# The reply packet is a MQTTv3 connack. But that the propose of this test,
127+
# ensure client convert it to a reason code 132 "Unsupported protocol version"
128+
connack_packet = paho_test.gen_connack(rc=1)
129+
count = fake_broker.send_packet(connack_packet)
130+
assert count # Check connection was not closed
131+
assert count == len(connack_packet)
132+
133+
packet_in = fake_broker.receive_packet(1)
134+
assert not packet_in # Check connection is closed
135+
136+
finally:
137+
mqttc.loop_stop()
138+
139+
95140
class TestPublishBroker2Client:
96141

97142
def test_invalid_utf8_topic(self, fake_broker):

0 commit comments

Comments
 (0)