01-no-clean-session.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/usr/bin/env python3
  2. # Test whether a client produces a correct connect with clean session not set.
  3. # The client should connect to port 1888 with keepalive=60, clean session not
  4. # set, and client id 01-no-clean-session.
  5. from mosq_test_helper import *
  6. port = mosq_test.get_lib_port()
  7. rc = 1
  8. keepalive = 60
  9. connect_packet = mosq_test.gen_connect("01-no-clean-session", clean_session=False, keepalive=keepalive)
  10. sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  11. sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
  12. sock.settimeout(10)
  13. sock.bind(('', port))
  14. sock.listen(5)
  15. client_args = sys.argv[1:]
  16. env = dict(os.environ)
  17. env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
  18. try:
  19. pp = env['PYTHONPATH']
  20. except KeyError:
  21. pp = ''
  22. env['PYTHONPATH'] = '../../lib/python:'+pp
  23. client = mosq_test.start_client(filename=sys.argv[1].replace('/', '-'), cmd=client_args, env=env, port=port)
  24. try:
  25. (conn, address) = sock.accept()
  26. conn.settimeout(10)
  27. mosq_test.expect_packet(conn, "connect", connect_packet)
  28. rc = 0
  29. conn.close()
  30. except mosq_test.TestError:
  31. pass
  32. finally:
  33. client.terminate()
  34. client.wait()
  35. sock.close()
  36. exit(rc)