def stress_test(stress=5, messages=1000): h = host(timeout=TIMEOUT) h.start() clients = [] for i in range(stress): c = client(timeout=TIMEOUT).start() c.write("connected", True) clients.append(c) report("All sockets connected") s() for i in range(messages): for c in clients: c.write("Test{}".format(i), text) h.write_ALL("Test{}".format(i), text) report("All data written") s() for i in range(messages): assert (h.get_ALL("Test{}".format(i)) == [text] * stress) for i in range(messages): for c in clients: assert (c.get("Test{}".format(i)) == text) report("All data asserted") for c in clients: c.close() h.close()
def multi_host_stress_test(stress=5, messages=1000, ports=[8080, 8081, 8082]): hosts = [] for port in ports: hosts.append(host(timeout=TIMEOUT, port=port).start()) clients = [] for i in range(stress): for port in ports: c = client(timeout=TIMEOUT, port=port).start() c.write("connected", True) clients.append(c) report("All sockets connected") s() for i in range(messages): for c in clients: c.write("Test{}".format(i), text) for h in hosts: h.write_ALL("Test{}".format(i), text) report("All data written") s() for i in range(messages): for h in hosts: assert (h.get_ALL("Test{}".format(i)) == [text] * stress) for i in range(messages): for c in clients: assert (c.get("Test{}".format(i)) == text) report("All data asserted") for c in clients: c.close() for h in hosts: h.close()
def initialize(): h = host(timeout=TIMEOUT) c = client(timeout=TIMEOUT) report("Sockets initialized") h.start() c.start() report("Sockets started") return h, c
def test_connection_BOTH(): start = time.time() h = host(timeout=TIMEOUT) h.start() c = client(timeout=TIMEOUT) c.start() report("Sockets opened and started") assert h.opened assert c.opened s(TIMEOUT) assert len(h.getClients()) is 1 report("Open state verified") c.close() assert not c.opened and c.stopped h.close() report("Closed state verified") assert not h.opened and h.stopped success("Connection test Passed ({:.5f} sec)".format(time.time() - start))
def test_async_ordering(): start = time.time() h = host(timeout=TIMEOUT, open=False) c = client(timeout=TIMEOUT, open=False) assert (not h.opened) h.open() h.start() assert (h.opened) report("Host started") c.open() c.start() assert (c.opened) report("Client started") h.close() assert (h.stopped) report("Host closed") c.close() assert (c.stopped) report("Client closed") success("Async Ordering test Passed ({:.5f} sec)".format(time.time() - start))