| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
from mosq_test_helper import * |
| 6 |
|
| 7 |
def do_test(proto_ver): |
| 8 |
rc = 1 |
| 9 |
|
| 10 |
port = mosq_test.get_port() |
| 11 |
|
| 12 |
if proto_ver == 5: |
| 13 |
V = 'mqttv5' |
| 14 |
elif proto_ver == 4: |
| 15 |
V = 'mqttv311' |
| 16 |
else: |
| 17 |
V = 'mqttv31' |
| 18 |
|
| 19 |
env = { |
| 20 |
'XDG_CONFIG_HOME':'/tmp/missing' |
| 21 |
} |
| 22 |
env = mosq_test.env_add_ld_library_path(env) |
| •23 |
cmd = ['/usr/bin/mosquitto_pub', |
| 24 |
'-p', str(port), |
| 25 |
'-q', '1', |
| 26 |
'-t', '03/pub/qos1/test', |
| 27 |
'-m', 'message', |
| 28 |
'-V', V |
| 29 |
] |
| 30 |
|
| 31 |
mid = 1 |
| 32 |
publish_packet = mosq_test.gen_publish("03/pub/qos1/test", qos=1, mid=mid, payload="message", proto_ver=proto_ver) |
| 33 |
if proto_ver == 5: |
| 34 |
puback_packet = mosq_test.gen_puback(mid, proto_ver=proto_ver, reason_code=mqtt5_rc.NO_MATCHING_SUBSCRIBERS) |
| 35 |
else: |
| 36 |
puback_packet = mosq_test.gen_puback(mid, proto_ver=proto_ver) |
| 37 |
|
| 38 |
broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port) |
| 39 |
|
| 40 |
try: |
| 41 |
sock = mosq_test.sub_helper(port=port, topic="#", qos=1, proto_ver=proto_ver) |
| 42 |
|
| 43 |
pub = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env) |
| 44 |
pub_terminate_rc = 0 |
| 45 |
if mosq_test.wait_for_subprocess(pub): |
| 46 |
print("pub not terminated") |
| 47 |
pub_terminate_rc = 1 |
| 48 |
(stdo, stde) = pub.communicate() |
| 49 |
|
| 50 |
mosq_test.expect_packet(sock, "publish", publish_packet) |
| 51 |
rc = pub_terminate_rc |
| 52 |
sock.close() |
| 53 |
except mosq_test.TestError: |
| 54 |
pass |
| 55 |
except Exception as e: |
| 56 |
print(e) |
| 57 |
finally: |
| 58 |
broker.terminate() |
| 59 |
if mosq_test.wait_for_subprocess(broker): |
| 60 |
print("broker not terminated") |
| 61 |
if rc == 0: rc=1 |
| 62 |
(stdo, stde) = broker.communicate() |
| 63 |
if rc: |
| 64 |
print(stde.decode('utf-8')) |
| 65 |
print("proto_ver=%d" % (proto_ver)) |
| 66 |
exit(rc) |
| 67 |
|
| 68 |
|
| 69 |
do_test(proto_ver=3) |
| 70 |
do_test(proto_ver=4) |
| 71 |
do_test(proto_ver=5) |