|
|
|
@ -10,6 +10,30 @@ def write_config(filename, port):
|
|
|
|
|
f.write("allow_anonymous true\n")
|
|
|
|
|
f.write("max_connections 10\n")
|
|
|
|
|
|
|
|
|
|
def test_iteration(port, connect_packets_ok, connack_packets_ok, connect_packet_bad, connack_packet_bad):
|
|
|
|
|
socks = []
|
|
|
|
|
|
|
|
|
|
# Open all allowed connections, a limit of 10
|
|
|
|
|
for i in range(0, 10):
|
|
|
|
|
socks.append(mosq_test.do_client_connect(connect_packets_ok[i], connack_packets_ok[i], port=port))
|
|
|
|
|
|
|
|
|
|
# Try to open an 11th connection
|
|
|
|
|
try:
|
|
|
|
|
sock_bad = mosq_test.do_client_connect(connect_packet_bad, connack_packet_bad, port=port)
|
|
|
|
|
except (ConnectionResetError, BrokenPipeError):
|
|
|
|
|
# Expected behaviour
|
|
|
|
|
pass
|
|
|
|
|
except OSError as e:
|
|
|
|
|
if e.errno == errno.ENOTCONN:
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
raise e
|
|
|
|
|
|
|
|
|
|
# Close all allowed connections
|
|
|
|
|
for i in range(0, 10):
|
|
|
|
|
socks[i].close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def do_test():
|
|
|
|
|
rc = 1
|
|
|
|
|
|
|
|
|
@ -27,48 +51,19 @@ def do_test():
|
|
|
|
|
write_config(conf_file, port)
|
|
|
|
|
broker = mosq_test.start_broker(filename=os.path.basename(__file__), use_conf=True, port=port)
|
|
|
|
|
|
|
|
|
|
socks = []
|
|
|
|
|
try:
|
|
|
|
|
# Open all allowed connections, a limit of 10
|
|
|
|
|
for i in range(0, 10):
|
|
|
|
|
socks.append(mosq_test.do_client_connect(connect_packets_ok[i], connack_packets_ok[i], port=port))
|
|
|
|
|
|
|
|
|
|
# Try to open an 11th connection
|
|
|
|
|
try:
|
|
|
|
|
sock_bad = mosq_test.do_client_connect(connect_packet_bad, connack_packet_bad, port=port)
|
|
|
|
|
except (ConnectionResetError, BrokenPipeError):
|
|
|
|
|
# Expected behaviour
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
# Close all allowed connections
|
|
|
|
|
for i in range(0, 10):
|
|
|
|
|
socks[i].close()
|
|
|
|
|
test_iteration(port, connect_packets_ok, connack_packets_ok, connect_packet_bad, connack_packet_bad)
|
|
|
|
|
|
|
|
|
|
## Now repeat - check it works as before
|
|
|
|
|
|
|
|
|
|
if os.environ.get('MOSQ_USE_VALGRIND') is not None:
|
|
|
|
|
time.sleep(0.5)
|
|
|
|
|
|
|
|
|
|
# Open all allowed connections, a limit of 10
|
|
|
|
|
for i in range(0, 10):
|
|
|
|
|
socks.append(mosq_test.do_client_connect(connect_packets_ok[i], connack_packets_ok[i], port=port))
|
|
|
|
|
|
|
|
|
|
# Try to open an 11th connection
|
|
|
|
|
try:
|
|
|
|
|
sock_bad = mosq_test.do_client_connect(connect_packet_bad, connack_packet_bad, port=port)
|
|
|
|
|
except (ConnectionResetError, BrokenPipeError):
|
|
|
|
|
# Expected behaviour
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
# Close all allowed connections
|
|
|
|
|
for i in range(0, 10):
|
|
|
|
|
socks[i].close()
|
|
|
|
|
test_iteration(port, connect_packets_ok, connack_packets_ok, connect_packet_bad, connack_packet_bad)
|
|
|
|
|
|
|
|
|
|
rc = 0
|
|
|
|
|
except mosq_test.TestError:
|
|
|
|
|
pass
|
|
|
|
|
except Exception as err:
|
|
|
|
|
print(err)
|
|
|
|
|
finally:
|
|
|
|
|
os.remove(conf_file)
|
|
|
|
|
broker.terminate()
|
|
|
|
|