03-publish-qos0-no-payload.py 1.3 KB
Newer Older
1
#!/usr/bin/env python3
R
Roger Light 已提交
2 3 4 5 6 7 8 9 10 11 12

# Test whether a client sends a correct PUBLISH to a topic with QoS 0 and no payload.

# The client should connect to port 1888 with keepalive=60, clean session set,
# and client id publish-qos0-test-np
# The test will send a CONNACK message to the client with rc=0. Upon receiving
# the CONNACK and verifying that rc=0, the client should send a PUBLISH message
# to topic "pub/qos0/no-payload/test" with zero length payload and QoS=0. If
# rc!=0, the client should exit with an error.
# After sending the PUBLISH message, the client should send a DISCONNECT message.

13
import context
R
Roger Light 已提交
14
import paho_test
R
Roger Light 已提交
15 16 17

rc = 1
keepalive = 60
R
Roger Light 已提交
18 19
connect_packet = paho_test.gen_connect("publish-qos0-test-np", keepalive=keepalive)
connack_packet = paho_test.gen_connack(rc=0)
R
Roger Light 已提交
20

21
publish_packet = paho_test.gen_publish(u"pub/qos0/no-payload/test", qos=0)
R
Roger Light 已提交
22

R
Roger Light 已提交
23
disconnect_packet = paho_test.gen_disconnect()
R
Roger Light 已提交
24

25
sock = paho_test.create_server_socket()
R
Roger Light 已提交
26

27
client = context.start_client()
R
Roger Light 已提交
28 29 30 31 32

try:
    (conn, address) = sock.accept()
    conn.settimeout(10)

R
Roger A. Light 已提交
33
    paho_test.expect_packet(conn, "connect", connect_packet)
R
Roger A. Light 已提交
34
    conn.send(connack_packet)
R
Roger Light 已提交
35

R
Roger A. Light 已提交
36 37
    paho_test.expect_packet(conn, "publish", publish_packet)
    paho_test.expect_packet(conn, "disconnect", disconnect_packet)
R
Roger A. Light 已提交
38
    rc = 0
39

R
Roger Light 已提交
40 41 42 43 44 45 46
    conn.close()
finally:
    client.terminate()
    client.wait()
    sock.close()

exit(rc)