Ejemplo n.º 1
0
def test_disconnect(data_in):
    a = Comm()
    b = Comm()
    a.listen()
    b.connect(a.port)

    target_b = ('127.0.0.1', a.port)
    target_a = ('127.0.0.1', list(b.sockets.values())[0].getsockname()[1])
    data_in = 'disconnect test'

    b.send(data_in)
    
    # Simulate a loss of connection and packet
    time.sleep(0.1)
    b.sockets[target_b].shutdown(2)
    try:
        b.sockets[target_b].close()
    except KeyError:
        pass
    a.data_received.pop(target_a, None)
    a.sockets[target_a].shutdown(2)
    try:
        a.sockets[target_a].close()
    except KeyError:
        pass

    data_out = a.recv(timeout=0.5)
    assert data_out == data_in

    a.shutdown(); b.shutdown()
Ejemplo n.º 2
0
def test_SendMultipleDataMultipleClientWithTarget():
    a = Comm()
    b = Comm()
    c = Comm()
    d = Comm()
    e = Comm()
    a.listen()
    b.connect(a.port)
    c.connect(a.port)
    d.connect(a.port)
    e.connect(a.port)

    b.send(data[0])
    data_out = a.recv(timeout=0.5)
    assert data_out == data[0]

    c.send(data[1])
    data_out = a.recv(timeout=0.5)
    assert data_out == data[1]

    d.send(data[2])
    e.send(data[3])
    data_out1 = a.recv(timeout=0.5, source=("127.0.0.1", e.port))
    data_out2 = a.recv(timeout=0.5, source=("127.0.0.1", d.port))
    assert data_out1 in data[2:]
    assert data_out2 in data[2:]

    a.shutdown(); b.shutdown(); c.shutdown(); d.shutdown(); e.shutdown()
Ejemplo n.º 3
0
def test_disconnect(data_in):
    a = Comm()
    b = Comm()
    a.listen()
    b.connect(a.port)

    target_b = ('127.0.0.1', a.port)
    target_a = ('127.0.0.1', list(b.sockets.values())[0].getsockname()[1])
    data_in = 'disconnect test'

    b.send(data_in)

    # Simulate a loss of connection and packet
    time.sleep(0.1)
    b.sockets[target_b].shutdown(2)
    try:
        b.sockets[target_b].close()
    except KeyError:
        pass
    a.data_received.pop(target_a, None)
    a.sockets[target_a].shutdown(2)
    try:
        a.sockets[target_a].close()
    except KeyError:
        pass

    data_out = a.recv(timeout=0.5)
    assert data_out == data_in

    a.shutdown()
    b.shutdown()
Ejemplo n.º 4
0
def test_SendMultipleDataMultipleClientWithTarget():
    a = Comm()
    b = Comm()
    c = Comm()
    d = Comm()
    e = Comm()
    a.listen()
    b.connect(a.port)
    c.connect(a.port)
    d.connect(a.port)
    e.connect(a.port)

    b.send(data[0])
    data_out = a.recv(timeout=0.5)
    assert data_out == data[0]

    c.send(data[1])
    data_out = a.recv(timeout=0.5)
    assert data_out == data[1]

    d.send(data[2])
    e.send(data[3])
    data_out1 = a.recv(timeout=0.5, source=("127.0.0.1", e.port))
    data_out2 = a.recv(timeout=0.5, source=("127.0.0.1", d.port))
    assert data_out1 in data[2:]
    assert data_out2 in data[2:]

    a.shutdown()
    b.shutdown()
    c.shutdown()
    d.shutdown()
    e.shutdown()
Ejemplo n.º 5
0
def test_ShutdownClientServer():
    a = Comm()
    b = Comm()
    a.listen(31415)
    b.connect(31415)

    b.shutdown()
    a.shutdown()

    assert threading.active_count() <= 1
Ejemplo n.º 6
0
def test_ShutdownClientServer():
    a = Comm()
    b = Comm()
    a.listen(31415)
    b.connect(31415)

    b.shutdown()
    a.shutdown()

    assert threading.active_count() <= 1
Ejemplo n.º 7
0
def test_messageIDNonListening(data_in):
    a = Comm()
    b = Comm()
    a.listen()
    b.connect(a.port)
    a.shutdown()

    mid = b.send(data_in)
    b.recv(timeout=0.5)

    assert b.is_acknowledged(mid) == False
Ejemplo n.º 8
0
def test_SendToSingleClient(data_in):
    a = Comm()
    b = Comm()
    a.listen()
    b.connect(a.port)

    a.send(data_in)
    data_out = b.recv(timeout=0.5)
    assert data_in == data_out

    a.shutdown(); b.shutdown()
Ejemplo n.º 9
0
def test_SendToServer(data_in):
    a = Comm()
    b = Comm()
    a.listen()
    b.connect(a.port)

    b.send(data_in)
    data_out = a.recv(timeout=0.5)
    assert data_in == data_out

    b.shutdown(); a.shutdown()
Ejemplo n.º 10
0
def test_messageIDNonListening(data_in):
    a = Comm()
    b = Comm()
    a.listen()
    b.connect(a.port)
    a.shutdown()

    mid = b.send(data_in)
    b.recv(timeout=0.5)

    assert b.is_acknowledged(mid) == False
Ejemplo n.º 11
0
def test_compressionAndSecure(data_in):
    a = Comm(compress=COMP_ZLIB_DEFAULT, secure=True)
    b = Comm(compress=COMP_ZLIB_DEFAULT, secure=True)

    a.listen()
    b.connect(a.port)

    b.send(data_in)
    data_out = a.recv(timeout=0.5)
    assert data_out == data_in

    a.shutdown(); b.shutdown()
Ejemplo n.º 12
0
def test_SendToSingleClient(data_in):
    a = Comm()
    b = Comm()
    a.listen()
    b.connect(a.port)

    a.send(data_in)
    data_out = b.recv(timeout=0.5)
    assert data_in == data_out

    a.shutdown()
    b.shutdown()
Ejemplo n.º 13
0
def test_SendToServer(data_in):
    a = Comm()
    b = Comm()
    a.listen()
    b.connect(a.port)

    b.send(data_in)
    data_out = a.recv(timeout=0.5)
    assert data_in == data_out

    b.shutdown()
    a.shutdown()
Ejemplo n.º 14
0
def test_securityServer(data_in):
    a = Comm(secure=True)
    b = Comm(secure=True)

    a.listen()
    b.connect(a.port)

    a.send(data_in)
    data_out = b.recv(timeout=0.5)
    a.recv(timeout=0.5) # Test the acknowledgment
    assert data_out == data_in

    a.shutdown(); b.shutdown()
Ejemplo n.º 15
0
def test_compressionAndSecure(data_in):
    a = Comm(compress=COMP_ZLIB_DEFAULT, secure=True)
    b = Comm(compress=COMP_ZLIB_DEFAULT, secure=True)

    a.listen()
    b.connect(a.port)

    b.send(data_in)
    data_out = a.recv(timeout=0.5)
    assert data_out == data_in

    a.shutdown()
    b.shutdown()
Ejemplo n.º 16
0
def test_securityServer(data_in):
    a = Comm(secure=True)
    b = Comm(secure=True)

    a.listen()
    b.connect(a.port)

    a.send(data_in)
    data_out = b.recv(timeout=0.5)
    a.recv(timeout=0.5)  # Test the acknowledgment
    assert data_out == data_in

    a.shutdown()
    b.shutdown()
Ejemplo n.º 17
0
def test_SendMultipleTargets(data_in):
    a = Comm()
    b = Comm()
    c = Comm()
    d = Comm()
    a.listen()
    b.listen()
    c.listen()
    d.connect(a.port)
    d.connect(b.port)
    d.connect(c.port)

    targets = [('127.0.0.1', a.port), ('127.0.0.1', b.port)]

    d.send(data_in, target=targets)
    data_out1, data_out2, data_out3 = a.recv(timeout=0.5), b.recv(
        timeout=0.5), c.recv(timeout=0.1)
    assert data_in == data_out1
    assert data_in == data_out2
    assert data_out3 is None

    a.shutdown()
    b.shutdown()
    c.shutdown()
    d.shutdown()
Ejemplo n.º 18
0
def test_SendMultipleData(data_in1, data_in2):
    a = Comm()
    b = Comm()
    a.listen()
    b.connect(a.port)

    b.send(data_in1)
    b.send(data_in2)

    data_out1, data_out2 = a.recv(timeout=0.5), a.recv(timeout=0.5)

    assert data_in1 == data_out1
    assert data_in2 == data_out2

    a.shutdown(); b.shutdown()
Ejemplo n.º 19
0
def test_multipleListen(data_in):
    a = Comm()
    b = Comm()

    a.listen(12340)
    a.listen(12341)
    b.connect(12340)
    b.connect(12341)

    data_in = "test data"
    b.send(data_in)
    data_out1, data_out2 = a.recv(timeout=0.5), a.recv(timeout=0.5)
    assert data_in == data_out1
    assert data_in == data_out2

    a.shutdown(); b.shutdown()
Ejemplo n.º 20
0
def test_SendMultipleData():
    a = Comm()
    b = Comm()
    a.listen()
    b.connect(a.port)

    for y in range(10):
        for x in data:
            b.send(x)

    for y in range(10):
        for x in data:
            data_out = a.recv(timeout=0.5)
            assert x == data_out

    a.shutdown(); b.shutdown()
Ejemplo n.º 21
0
def test_SendMultipleData(data_in1, data_in2):
    a = Comm()
    b = Comm()
    a.listen()
    b.connect(a.port)

    b.send(data_in1)
    b.send(data_in2)

    data_out1, data_out2 = a.recv(timeout=0.5), a.recv(timeout=0.5)

    assert data_in1 == data_out1
    assert data_in2 == data_out2

    a.shutdown()
    b.shutdown()
Ejemplo n.º 22
0
def test_SendMultipleData():
    a = Comm()
    b = Comm()
    a.listen()
    b.connect(a.port)

    for y in range(10):
        for x in data:
            b.send(x)

    for y in range(10):
        for x in data:
            data_out = a.recv(timeout=0.5)
            assert x == data_out

    a.shutdown()
    b.shutdown()
Ejemplo n.º 23
0
def test_multipleListen(data_in):
    a = Comm()
    b = Comm()

    a.listen(12340)
    a.listen(12341)
    b.connect(12340)
    b.connect(12341)

    data_in = "test data"
    b.send(data_in)
    data_out1, data_out2 = a.recv(timeout=0.5), a.recv(timeout=0.5)
    assert data_in == data_out1
    assert data_in == data_out2

    a.shutdown()
    b.shutdown()
Ejemplo n.º 24
0
def test_messageIDInterruption(data_in):
    a = Comm()
    b = Comm()
    a.listen()
    serv_port = a.port
    b.connect(serv_port)
    a.shutdown()

    mid = b.send(data_in)
    b.recv(timeout=0.5)

    assert b.is_acknowledged(mid) == False

    a.listen(serv_port)
    b.recv(timeout=0.5)

    assert b.is_acknowledged(mid) == False

    a.recv(timeout=0.5)
    b.recv(timeout=0.5)

    assert b.is_acknowledged(mid) == True
Ejemplo n.º 25
0
def test_messageIDInterruption(data_in):
    a = Comm()
    b = Comm()
    a.listen()
    serv_port = a.port
    b.connect(serv_port)
    a.shutdown()

    mid = b.send(data_in)
    b.recv(timeout=0.5)

    assert b.is_acknowledged(mid) == False

    a.listen(serv_port)
    b.recv(timeout=0.5)

    assert b.is_acknowledged(mid) == False

    a.recv(timeout=0.5)
    b.recv(timeout=0.5)

    assert b.is_acknowledged(mid) == True
Ejemplo n.º 26
0
def test_CreateTwoServersBackToBack():
    a = Comm()
    b = Comm()
    c = Comm()

    a.listen()
    a.shutdown()
    b.listen(a.port)
    c.connect(b.port)

    c.send(data[0])
    data_out = b.recv(timeout=0.5)
    assert data[0] == data_out

    a.shutdown(); b.shutdown(); c.shutdown()
Ejemplo n.º 27
0
def test_CreateTwoServersBackToBack():
    a = Comm()
    b = Comm()
    c = Comm()

    a.listen()
    a.shutdown()
    b.listen(a.port)
    c.connect(b.port)

    c.send(data[0])
    data_out = b.recv(timeout=0.5)
    assert data[0] == data_out

    a.shutdown()
    b.shutdown()
    c.shutdown()
Ejemplo n.º 28
0
def test_ShutdownMultiple():
    a = Comm()
    b = Comm()
    c = Comm()
    a.listen(27182)
    b.connect(27182)
    c.connect(27182)

    c.shutdown()
    b.shutdown()
    a.shutdown()

    assert threading.active_count() <= 1
Ejemplo n.º 29
0
def test_ShutdownMultiple():
    a = Comm()
    b = Comm()
    c = Comm()
    a.listen(27182)
    b.connect(27182)
    c.connect(27182)

    c.shutdown()
    b.shutdown()
    a.shutdown()

    assert threading.active_count() <= 1
Ejemplo n.º 30
0
def test_SendMultipleTargets(data_in):
    a = Comm()
    b = Comm()
    c = Comm()
    d = Comm()
    a.listen()
    b.listen()
    c.listen()
    d.connect(a.port)
    d.connect(b.port)
    d.connect(c.port)

    targets = [('127.0.0.1', a.port), ('127.0.0.1', b.port)]

    d.send(data_in, target=targets)
    data_out1, data_out2, data_out3 = a.recv(timeout=0.5), b.recv(timeout=0.5), c.recv(timeout=0.1)
    assert data_in == data_out1
    assert data_in == data_out2
    assert data_out3 is None

    a.shutdown(); b.shutdown(); c.shutdown(); d.shutdown()
Ejemplo n.º 31
0
def test_SendToAllServers(data_in):
    # Testing multiple connection sending by a client
    a = Comm()
    b = Comm()
    c = Comm()
    a.listen()
    b.listen()
    c.connect(a.port)
    c.connect(b.port)

    c.send(data_in)
    data_out1, data_out2 = a.recv(timeout=0.5), b.recv(timeout=0.5)
    assert data_in == data_out1
    assert data_in == data_out2

    a.shutdown(); b.shutdown(); c.shutdown()
Ejemplo n.º 32
0
def test_SendToAllClients(data_in):
    # Testing broadcast

    a = Comm()
    b = Comm()
    c = Comm()

    a.listen()
    b.connect(a.port)
    c.connect(a.port)

    a.send(data_in)
    data_out1, data_out2 = b.recv(timeout=0.5), c.recv(timeout=0.5)
    assert data_in == data_out1 == data_out2

    a.shutdown(); b.shutdown(); c.shutdown()
Ejemplo n.º 33
0
def test_SendTarget(data_in):
    a = Comm()
    b = Comm()
    c = Comm()
    a.listen()
    b.listen()
    c.connect(a.port)
    c.connect(b.port)

    target = ('127.0.0.1', a.port)

    c.send(data_in, target=target)
    data_out1, data_out2 = a.recv(timeout=0.5), b.recv(timeout=0.1)
    assert data_out1 == data_in
    assert data_out2 is None

    a.shutdown(); b.shutdown(); c.shutdown()
Ejemplo n.º 34
0
def test_SendToAllClients(data_in):
    # Testing broadcast

    a = Comm()
    b = Comm()
    c = Comm()

    a.listen()
    b.connect(a.port)
    c.connect(a.port)

    a.send(data_in)
    data_out1, data_out2 = b.recv(timeout=0.5), c.recv(timeout=0.5)
    assert data_in == data_out1 == data_out2

    a.shutdown()
    b.shutdown()
    c.shutdown()
Ejemplo n.º 35
0
def test_SendToAllServers(data_in):
    # Testing multiple connection sending by a client
    a = Comm()
    b = Comm()
    c = Comm()
    a.listen()
    b.listen()
    c.connect(a.port)
    c.connect(b.port)

    c.send(data_in)
    data_out1, data_out2 = a.recv(timeout=0.5), b.recv(timeout=0.5)
    assert data_in == data_out1
    assert data_in == data_out2

    a.shutdown()
    b.shutdown()
    c.shutdown()
Ejemplo n.º 36
0
def test_SendTarget(data_in):
    a = Comm()
    b = Comm()
    c = Comm()
    a.listen()
    b.listen()
    c.connect(a.port)
    c.connect(b.port)

    target = ('127.0.0.1', a.port)

    c.send(data_in, target=target)
    data_out1, data_out2 = a.recv(timeout=0.5), b.recv(timeout=0.1)
    assert data_out1 == data_in
    assert data_out2 is None

    a.shutdown()
    b.shutdown()
    c.shutdown()
Ejemplo n.º 37
0
def test_ShutdownSimple():
    a = Comm()

    a.shutdown()

    assert threading.active_count() <= 1
Ejemplo n.º 38
0
def test_ShutdownSimple():
    a = Comm()

    a.shutdown()

    assert threading.active_count() <= 1