Example #1
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))
Example #2
0
def test_connection_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.connections) is 1)
    assert (len(h2.connections) is 1)
    c1 = h1.connections[0]
    c2 = h2.connections[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))
Example #3
0
def initialize():
    h1 = hub(timeout=TIMEOUT)
    h2 = hub(timeout=TIMEOUT)
    h1.connect(CHANNEL, '127.0.0.1', h2.port)
    report("Hubs created and started")
    s(0.1)
    return h1, h2
Example #4
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.connections) == 2 * stress)
    report("Hub connections 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()
Example #5
0
def multi_connections(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.connections) == len(h2.connections))
    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()
Example #6
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))
Example #7
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.connections) == len(h2.connections))
    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()
Example #8
0
def test_hub_connection_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.connections) is 1)
    assert (len(h2.connections) 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))
Example #9
0
def get_video():
    h = hub(port=8081)
    print("Started hub on port", h.port)
    while h.connections == []:
        pass
    c = h.connections[0]
    print("Starting capture")
    while c.getImg() is None:
        pass
    while True:
        key = cv2.waitKey(1) & 0xff
        if key == ord('q'):
            cv2.destroyAllWindows()
            h.close()
            break
        cv2.imshow("Stream", c.getImg())
Example #10
0
def send_video():
    h = hub(port=8080)
    print("Started hub on port", h.port)
    h.connect("video", '127.0.0.1', 8081)
    print("Connected!")
    sleep(2)
    c = h.connections[0]
    cam = cv2.VideoCapture(2)
    while True:
        ret, frame = cam.read()
        if not COLOR:
            frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
        frame = cv2.resize(frame, SIZE)
        cv2.imshow("Sending", frame)
        key = cv2.waitKey(1) & 0xff
        if key == ord('q'):
            cv2.destroyAllWindows()
            h.close()
            break
        c.writeImg(frame)
 def __init__(self, guid, addr, port):
     self.guid = guid
     self.addr = addr
     self.port = port
     self.names = 0
     self.socket = hub(port)