Debian Codegraph @

test/client/03-publish-qos1-ws-large.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
32 payload = "abcdefghijklmnopqrstuvwxyz0123456789"*1821
33
34 cmd = [f'{mosq_test.get_build_root()}/client/mosquitto_pub',
35 '-p', str(ports[0]),
36 '-q', '1',
37 '-t', '03/pub/qos1/test',
38 '-m', payload,
39 '-V', V,
40 '--ws'
41 ]
42
43 mid = 1
44 publish_packet = mosq_test.gen_publish("03/pub/qos1/test", qos=1, mid=mid, payload=payload, proto_ver=proto_ver)
45 if proto_ver == 5:
46 puback_packet = mosq_test.gen_puback(mid, proto_ver=proto_ver, reason_code=mqtt5_rc.NO_MATCHING_SUBSCRIBERS)
47 else:
48 puback_packet = mosq_test.gen_puback(mid, proto_ver=proto_ver)
49
50 write_config(conf_file, ports[0], ports[1])
51
52 try:
53 broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=ports[1], use_conf=True)
54 sock = mosq_test.sub_helper(port=ports[1], topic="#", qos=1, proto_ver=proto_ver)
55
56 pub = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env)
57 pub_terminate_rc = 0
58 if mosq_test.wait_for_subprocess(pub):
59 print("pub not terminated")
60 pub_terminate_rc = 1
61 (stdo, stde) = pub.communicate()
62
63 mosq_test.expect_packet(sock, "publish", publish_packet)
64 rc = pub_terminate_rc
65 sock.close()
66 except mosq_test.TestError:
67 pass
68 except Exception as e:
69 print(e)
70 finally:
71 broker.terminate()
72 os.remove(conf_file)
73 if mosq_test.wait_for_subprocess(broker):
74 print("broker not terminated")
75 if rc == 0: rc=1
76 (stdo, stde) = broker.communicate()
77 if rc:
78 print(stde.decode('utf-8'))
79 print("proto_ver=%d" % (proto_ver))
80 exit(rc)
81
82
83 do_test(proto_ver=3)
84 do_test(proto_ver=4)
85 do_test(proto_ver=5)