12-prop-server-keepalive.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/usr/bin/env python3
  2. # Test whether sending a non zero session expiry interval in DISCONNECT after
  3. # having sent a zero session expiry interval is treated correctly in MQTT v5.
  4. from mosq_test_helper import *
  5. def write_config(filename, port):
  6. with open(filename, 'w') as f:
  7. f.write("port %d\n" % (port))
  8. f.write("allow_anonymous true\n")
  9. f.write("\n")
  10. f.write("max_keepalive 60\n")
  11. port = mosq_test.get_port(1)
  12. conf_file = os.path.basename(__file__).replace('.py', '.conf')
  13. write_config(conf_file, port)
  14. rc = 1
  15. keepalive = 61
  16. connect_packet = mosq_test.gen_connect("test", proto_ver=5, keepalive=keepalive)
  17. props = mqtt5_props.gen_uint16_prop(mqtt5_props.PROP_SERVER_KEEP_ALIVE, 60) \
  18. + mqtt5_props.gen_uint16_prop(mqtt5_props.PROP_TOPIC_ALIAS_MAXIMUM, 10) \
  19. + mqtt5_props.gen_uint16_prop(mqtt5_props.PROP_RECEIVE_MAXIMUM, 20)
  20. connack_packet = mosq_test.gen_connack(rc=0, proto_ver=5, properties=props, property_helper=False)
  21. broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port, use_conf=True)
  22. try:
  23. sock = mosq_test.do_client_connect(connect_packet, connack_packet, port=port)
  24. sock.close()
  25. rc = 0
  26. except mosq_test.TestError:
  27. pass
  28. finally:
  29. os.remove(conf_file)
  30. broker.terminate()
  31. broker.wait()
  32. (stdo, stde) = broker.communicate()
  33. if rc:
  34. print(stde.decode('utf-8'))
  35. exit(rc)