def multi_hub_stress_test(stress=5, messages=1000): hubs = [] for i in range(stress): h = Hub(timeout=TIMEOUT) hubs.append(h) report("Hubs created") for h1 in hubs: for h2 in hubs: h2.connect("Test", "127.0.0.1", h1.port) report("Hubs linked") s() for h in hubs: assert len(h.transports) == 2 * stress report("Hub transports verified") for h in hubs: for i in range(messages): h.write_all("Test{}".format(i), text) report("Writing finished") s() for h in hubs: for i in range(messages): assert h.get_all("Test{}".format(i)) == [text] * 2 * stress report("Hub messages verified") for h in hubs: h.close()
def multi_transports(num_conn=10, messages=10, bidirectional=False): h1 = Hub(timeout=TIMEOUT) h2 = Hub(timeout=TIMEOUT) for i in range(num_conn): h1.connect("Test{}".format(i), "127.0.0.1", h2.port) s() assert len(h1.transports) == len(h2.transports) for i in range(messages): h1.write_all("Test{}".format(i), text) if bidirectional: h2.write_all("Test{}".format(i), text) s() for i in range(messages): if bidirectional: assert h1.get_all("Test{}".format(i)) == [text] * num_conn assert h2.get_all("Test{}".format(i)) == [text] * num_conn h1.close() h2.close()
def stress_test(stress=5, messages=1000): h1 = Hub(timeout=TIMEOUT) h2 = Hub(timeout=TIMEOUT) for i in range(stress): if i % 2 == 0: h1.connect("Test{}".format(i), "127.0.0.1", h2.port) else: h2.connect("Test{}".format(i), "127.0.0.1", h1.port) s() assert len(h1.transports) == len(h2.transports) for i in range(messages): h1.write_all("Test{}".format(i), text) h2.write_all("Test{}".format(i), text) s() for i in range(messages): assert h1.get_all("Test{}".format(i)) == [text] * stress assert h2.get_all("Test{}".format(i)) == [text] * stress h1.close() h2.close()