mosquitto/test/broker/03-publish-c2b-timeout-qos2.py

43 lines
1.2 KiB
Python
Raw Normal View History

2019-03-28 21:32:12 +00:00
#!/usr/bin/env python3
2014-05-07 22:27:00 +00:00
# Test whether a PUBLISH to a topic with QoS 2 results in the correct packet
# flow. This test introduces delays into the flow in order to force the broker
# to send duplicate PUBREC and PUBCOMP messages.
2018-11-27 11:26:21 +00:00
from mosq_test_helper import *
2014-05-07 22:27:00 +00:00
rc = 1
keepalive = 600
connect_packet = mosq_test.gen_connect("pub-qos2-timeout-test", keepalive=keepalive)
connack_packet = mosq_test.gen_connack(rc=0)
mid = 1926
publish_packet = mosq_test.gen_publish("pub/qos2/test", qos=2, mid=mid, payload="timeout-message")
pubrec_packet = mosq_test.gen_pubrec(mid)
pubrel_packet = mosq_test.gen_pubrel(mid)
pubcomp_packet = mosq_test.gen_pubcomp(mid)
2014-06-26 22:12:55 +00:00
broker = mosq_test.start_broker(filename=os.path.basename(__file__))
2014-05-07 22:27:00 +00:00
try:
sock = mosq_test.do_client_connect(connect_packet, connack_packet)
mosq_test.do_send_receive(sock, publish_packet, pubrec_packet, "pubrec")
2014-05-07 22:27:00 +00:00
# Timeout is 8 seconds which means the broker should repeat the PUBREC.
2014-05-07 22:27:00 +00:00
if mosq_test.expect_packet(sock, "pubrec", pubrec_packet):
mosq_test.do_send_receive(sock, pubrel_packet, pubcomp_packet, "pubcomp")
2014-05-07 22:27:00 +00:00
rc = 0
2014-05-07 22:27:00 +00:00
sock.close()
finally:
broker.terminate()
broker.wait()
(stdo, stde) = broker.communicate()
2014-05-07 22:27:00 +00:00
if rc:
print(stde)
exit(rc)