| 1 |
|
| 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 |
payload = "message" |
| •32 |
cmd = ['/usr/bin/mosquitto_rr', |
| 33 |
'-p', str(ports[0]), |
| 34 |
'-q', '1', |
| 35 |
'-t', '04/rr/qos1/test/request', |
| 36 |
'-e', '04/rr/qos1/test/response', |
| 37 |
'-V', V, |
| 38 |
'-m', payload, |
| 39 |
'--ws' |
| 40 |
] |
| 41 |
|
| 42 |
if proto_ver == 5: |
| 43 |
props = mqtt5_props.gen_string_prop(mqtt5_props.RESPONSE_TOPIC, "04/rr/qos1/test/response") |
| 44 |
else: |
| 45 |
props = None |
| 46 |
publish_packet_req = mosq_test.gen_publish("04/rr/qos1/test/request", qos=1, mid=1, payload=payload, proto_ver=proto_ver, properties=props) |
| 47 |
payload = "the response" |
| 48 |
publish_packet_resp = mosq_test.gen_publish("04/rr/qos1/test/response", qos=1, mid=2, payload=payload, proto_ver=proto_ver) |
| 49 |
puback_packet_req = mosq_test.gen_puback(1, proto_ver=proto_ver) |
| 50 |
puback_packet_resp = mosq_test.gen_puback(2, proto_ver=proto_ver) |
| 51 |
|
| 52 |
write_config(conf_file, ports[0], ports[1]) |
| 53 |
|
| 54 |
try: |
| 55 |
broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=ports[1], use_conf=True) |
| 56 |
sock = mosq_test.sub_helper(port=ports[1], topic="04/rr/qos1/test/request", qos=1, proto_ver=proto_ver) |
| 57 |
|
| 58 |
rr = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env) |
| 59 |
|
| 60 |
mosq_test.expect_packet(sock, "publish", publish_packet_req) |
| 61 |
sock.send(puback_packet_req) |
| 62 |
|
| 63 |
sock.send(publish_packet_resp) |
| 64 |
mosq_test.expect_packet(sock, "puback", puback_packet_resp) |
| 65 |
|
| 66 |
time.sleep(0.1) |
| 67 |
rr_terminate_rc = 0 |
| 68 |
if mosq_test.wait_for_subprocess(rr): |
| 69 |
print("rr not terminated") |
| 70 |
rr_terminate_rc = 1 |
| 71 |
(stdo, stde) = rr.communicate() |
| 72 |
if stdo.decode('utf-8') == payload + '\n': |
| 73 |
rc = rr_terminate_rc |
| 74 |
sock.close() |
| 75 |
except mosq_test.TestError: |
| 76 |
pass |
| 77 |
except Exception as e: |
| 78 |
print(e) |
| 79 |
finally: |
| 80 |
broker.terminate() |
| 81 |
os.remove(conf_file) |
| 82 |
if mosq_test.wait_for_subprocess(broker): |
| 83 |
print("broker not terminated") |
| 84 |
if rc == 0: rc=1 |
| 85 |
(stdo, stde) = broker.communicate() |
| 86 |
if rc: |
| 87 |
print(stde.decode('utf-8')) |
| 88 |
print("proto_ver=%d" % (proto_ver)) |
| 89 |
exit(rc) |
| 90 |
|
| 91 |
|
| 92 |
do_test(proto_ver=3) |
| 93 |
do_test(proto_ver=4) |
| 94 |
do_test(proto_ver=5) |