forked from eclipse/mosquitto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
03-publish-b2c-timeout-qos2.py
executable file
·57 lines (42 loc) · 1.97 KB
/
03-publish-b2c-timeout-qos2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python3
# Test whether a SUBSCRIBE to a topic with QoS 2 results in the correct SUBACK packet.
from mosq_test_helper import *
rc = 1
mid = 3265
keepalive = 60
connect_packet = mosq_test.gen_connect("pub-qo2-timeout-test", keepalive=keepalive)
connack_packet = mosq_test.gen_connack(rc=0)
subscribe_packet = mosq_test.gen_subscribe(mid, "qos2/timeout/test", 2)
suback_packet = mosq_test.gen_suback(mid, 2)
mid = 1
publish_packet = mosq_test.gen_publish("qos2/timeout/test", qos=2, mid=mid, payload="timeout-message")
publish_dup_packet = mosq_test.gen_publish("qos2/timeout/test", qos=2, mid=mid, payload="timeout-message", dup=True)
pubrec_packet = mosq_test.gen_pubrec(mid)
pubrel_packet = mosq_test.gen_pubrel(mid)
pubcomp_packet = mosq_test.gen_pubcomp(mid)
broker = mosq_test.start_broker(filename=os.path.basename(__file__))
try:
sock = mosq_test.do_client_connect(connect_packet, connack_packet)
mosq_test.do_send_receive(sock, subscribe_packet, suback_packet, "suback")
pub = subprocess.Popen(['./03-publish-b2c-timeout-qos2-helper.py'], stdout=subprocess.PIPE, stderr=subprocess.PIPE))
pub.wait()
(stdo, stde) = pub.communicate()
# Should have now received a publish command
if mosq_test.expect_packet(sock, "publish", publish_packet):
# Wait for longer than 5 seconds to get republish with dup set
# This is covered by the 8 second timeout
if mosq_test.expect_packet(sock, "dup publish", publish_dup_packet):
mosq_test.do_send_receive(sock, pubrec_packet, pubrel_packet, "pubrel")
# Wait for longer than 5 seconds to get republish with dup set
# This is covered by the 8 second timeout
if mosq_test.expect_packet(sock, "dup pubrel", pubrel_packet):
sock.send(pubcomp_packet)
rc = 0
sock.close()
finally:
broker.terminate()
broker.wait()
(stdo, stde) = broker.communicate()
if rc:
print(stde.decode('utf-8'))
exit(rc)