Beispiel #1
0
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()
Beispiel #2
0
def test_transport_setup():
    start = time.time()
    h1 = Hub(timeout=TIMEOUT)
    h2 = Hub(timeout=TIMEOUT)
    report("Hubs created and started")
    h1.connect(CHANNEL, "127.0.0.1", h2.port)
    s(0.1)
    assert len(h1.transports) is 1
    assert len(h2.transports) is 1
    c1 = h1.transports[0]
    c2 = h2.transports[0]
    assert c1.opened
    assert not c1.stopped
    assert c2.opened
    assert not c2.stopped
    assert c1.name == CHANNEL
    assert c2.name == CHANNEL
    assert c1.addr == "127.0.0.1"
    assert c2.addr == "127.0.0.1"
    h1.close()
    h2.close()
    s(TIMEOUT)
    assert not c1.opened
    assert c1.stopped
    assert not c2.opened
    assert c2.stopped
    success("Connection Setup Test Passed ({:.5f} sec)".format(time.time() -
                                                               start))
Beispiel #3
0
def test_oneway_messages():
    start = time.time()
    h1 = Hub(timeout=TIMEOUT)
    h2 = Hub(timeout=TIMEOUT)
    assert h1.get_all("Test") == []
    assert h2.get_all("Test") == []
    assert h1.get_all("Test2") == []
    assert h2.get_all("Test2") == []
    h1.connect("Test", "127.0.0.1", h2.port)
    s(0.1)
    h1.write_to_name("Test", "Test", "test of port 1")
    s(0.05)
    assert h1.get_all("Test") == []
    assert h2.get_all("Test") == ["test of port 1"]
    assert h1.get_all("Test2") == []
    assert h2.get_all("Test2") == []
    h1.write_to_name("Test", "Test2", "test of port 2")
    s(0.05)
    assert h1.get_all("Test") == []
    assert h2.get_all("Test") == ["test of port 1"]
    assert h1.get_all("Test2") == []
    assert h2.get_all("Test2") == ["test of port 2"]
    h1.close()
    h2.close()
    success("One-way messages Test Passed ({:.5f} sec)".format(time.time() -
                                                               start))
Beispiel #4
0
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()
Beispiel #5
0
def test_empty_messages():
    start = time.time()
    h1 = Hub(timeout=TIMEOUT)
    h2 = Hub(timeout=TIMEOUT)
    assert h1.get_all("Test") == []
    assert h2.get_all("Test") == []
    assert h1.get_all("Test2") == []
    assert h2.get_all("Test2") == []
    h1.connect("Test", "127.0.0.1", h2.port)
    s(0.1)
    assert h1.get_all("Test") == []
    assert h2.get_all("Test") == []
    assert h1.get_all("Test2") == []
    assert h2.get_all("Test2") == []
    h1.close()
    h2.close()
    success("Empty messages Test Passed ({:.5f} sec)".format(time.time() -
                                                             start))
Beispiel #6
0
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()
Beispiel #7
0
def test_hub_transport_setup():
    start = time.time()
    h1 = Hub(timeout=TIMEOUT)
    h2 = Hub(timeout=TIMEOUT)
    report("Hubs created and started")
    assert h1.opened
    assert not h1.stopped
    assert h2.opened
    assert not h2.stopped
    h1.connect(CHANNEL, "127.0.0.1", h2.port)
    s(0.1)
    assert len(h1.transports) is 1
    assert len(h2.transports) is 1
    h1.close()
    h2.close()
    assert not h1.opened
    assert h1.stopped
    assert not h2.opened
    assert h1.stopped
    success(
        "Hub Connection Setup Test Passed ({:.5f} sec)".format(time.time() -
                                                               start))