Debian Codegraph @

test/client/03-publish-qos1-ws.py

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 #!/usr/bin/env python3
2
3 #
4
5 from mosq_test_helper import *
6
7 def write_config(filename, port1, port2):
8 with open(filename, 'w') as f:
9 f.write("allow_anonymous true\n")
10 f.write(f"listener {port1}\n")
11 f.write("protocol websockets\n")
12 f.write(f"listener {port2}\n")
13
14 def do_test(proto_ver):
15 rc = 1
16
17 ports = mosq_test.get_port(2)
18 conf_file = os.path.basename(__file__).replace('.py', '.conf')
19
20 if proto_ver == 5:
21 V = 'mqttv5'
22 elif proto_ver == 4:
23 V = 'mqttv311'
24 else:
25 V = 'mqttv31'
26
27 env = {
28 'XDG_CONFIG_HOME':'/tmp/missing'
29 }
30 env = mosq_test.env_add_ld_library_path(env)
31 cmd = [f'{mosq_test.get_build_root()}/client/mosquitto_pub',
32 '-p', str(ports[0]),
33 '-q', '1',
34 '-t', '03/pub/qos1/test',
35 '-m', 'message',
36 '-V', V,
37 '--ws'
38 ]
39
40 mid = 1
41 publish_packet = mosq_test.gen_publish("03/pub/qos1/test", qos=1, mid=mid, payload="message", proto_ver=proto_ver)
42 if proto_ver == 5:
43 puback_packet = mosq_test.gen_puback(mid, proto_ver=proto_ver, reason_code=mqtt5_rc.NO_MATCHING_SUBSCRIBERS)
44 else:
45 puback_packet = mosq_test.gen_puback(mid, proto_ver=proto_ver)
46
47 write_config(conf_file, ports[0], ports[1])
48
49 try:
50 broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=ports[1], use_conf=True)
51 sock = mosq_test.sub_helper(port=ports[1], topic="#", qos=1, proto_ver=proto_ver)
52
53 pub = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env)
54 pub_terminate_rc = 0
55 if mosq_test.wait_for_subprocess(pub):
56 print("pub not terminated")
57 pub_terminate_rc = 1
58 (stdo, stde) = pub.communicate()
59
60 mosq_test.expect_packet(sock, "publish", publish_packet)
61 rc = pub_terminate_rc
62 sock.close()
63 except mosq_test.TestError:
64 pass
65 except Exception as e:
66 print(e)
67 finally:
68 broker.terminate()
69 os.remove(conf_file)
70 if mosq_test.wait_for_subprocess(broker):
71 print("broker not terminated")
72 if rc == 0: rc=1
73 (stdo, stde) = broker.communicate()
74 if rc:
75 print(stde.decode('utf-8'))
76 print("proto_ver=%d" % (proto_ver))
77 exit(rc)
78
79
80 do_test(proto_ver=3)
81 do_test(proto_ver=4)
82 do_test(proto_ver=5)