Add test for multiple unsubscribe.
This commit is contained in:
parent
e1976739b8
commit
219f47b07f
34
test/broker/02-unsubscribe-qos2-multiple.py
Executable file
34
test/broker/02-unsubscribe-qos2-multiple.py
Executable file
@ -0,0 +1,34 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Test whether a SUBSCRIBE to multiple topics with QoS 2 results in the correct SUBACK packet.
|
||||
|
||||
from mosq_test_helper import *
|
||||
|
||||
rc = 1
|
||||
mid = 3
|
||||
keepalive = 60
|
||||
connect_packet = mosq_test.gen_connect("unsubscribe-qos2-test", keepalive=keepalive)
|
||||
connack_packet = mosq_test.gen_connack(rc=0)
|
||||
|
||||
unsubscribe_packet = mosq_test.gen_unsubscribe_multiple(mid, ["qos2/one", "qos2/two"])
|
||||
unsuback_packet = mosq_test.gen_unsuback(mid)
|
||||
|
||||
port = mosq_test.get_port()
|
||||
broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port)
|
||||
|
||||
try:
|
||||
sock = mosq_test.do_client_connect(connect_packet, connack_packet, port=port)
|
||||
mosq_test.do_send_receive(sock, unsubscribe_packet, unsuback_packet, "unsuback")
|
||||
|
||||
rc = 0
|
||||
|
||||
sock.close()
|
||||
finally:
|
||||
broker.terminate()
|
||||
broker.wait()
|
||||
(stdo, stde) = broker.communicate()
|
||||
if rc:
|
||||
print(stde)
|
||||
|
||||
exit(rc)
|
||||
|
@ -69,6 +69,7 @@ endif
|
||||
./02-unsubscribe-qos2.py
|
||||
./02-unsubscribe-qos2-v5.py
|
||||
./02-unsubscribe-invalid-no-topic.py
|
||||
./02-unsubscribe-qos2-multiple.py
|
||||
./02-subscribe-invalid-utf8.py
|
||||
./02-subscribe-persistence-flipflop.py
|
||||
./02-subhier-crash.py
|
||||
|
@ -52,6 +52,7 @@ tests = [
|
||||
(1, './02-unsubscribe-qos2.py'),
|
||||
(1, './02-unsubscribe-qos2-v5.py'),
|
||||
(1, './02-unsubscribe-invalid-no-topic.py'),
|
||||
(1, './02-unsubscribe-qos2-multiple.py'),
|
||||
(1, './02-subscribe-invalid-utf8.py'),
|
||||
(1, './02-subscribe-persistence-flipflop.py'),
|
||||
(1, './02-subhier-crash.py'),
|
||||
|
@ -478,6 +478,24 @@ def gen_unsubscribe(mid, topic, proto_ver=4):
|
||||
pack_format = "!BBHH"+str(len(topic))+"s"
|
||||
return struct.pack(pack_format, 162, 2+2+len(topic), mid, len(topic), topic)
|
||||
|
||||
def gen_unsubscribe_multiple(mid, topics, proto_ver=4):
|
||||
packet = ""
|
||||
remaining_length = 0
|
||||
for t in topics:
|
||||
remaining_length += 2+len(t)
|
||||
print(t)
|
||||
packet += struct.pack("!H"+str(len(t))+"s", len(t), t)
|
||||
print(packet)
|
||||
|
||||
if proto_ver == 5:
|
||||
remaining_length += 2+1
|
||||
|
||||
return struct.pack("!BBHB", 162, remaining_length, mid, 0) + packet
|
||||
else:
|
||||
remaining_length += 2
|
||||
|
||||
return struct.pack("!BBH", 162, remaining_length, mid) + packet
|
||||
|
||||
def gen_unsuback(mid, proto_ver=4):
|
||||
if proto_ver == 5:
|
||||
return struct.pack('!BBHB', 176, 3, mid, 0)
|
||||
|
Loading…
Reference in New Issue
Block a user