def test_SendMultipleDataMultipleClient(): a = Socket() b = Socket() c = Socket() d = Socket() e = Socket() 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.receive() assert data_out == data[0] c.send(data[1]) data_out = a.receive() assert data_out == data[1] d.send(data[2]) e.send(data[3]) data_out1 = a.receive() data_out2 = a.receive() assert data_out1 == data[2] assert data_out2 == data[3] a.shutdown(); b.shutdown(); c.shutdown(); d.shutdown(); e.shutdown()
def test_disconnect(): a = Socket() b = Socket() a.listen() b.connect(a.port) time.sleep(0.1) target = ('127.0.0.1', a.port) sock = b.sockets[target] data_in = 'disconnect test' data_serialized = b._prepareData(data_in, target) data_header = struct.pack('!IH', len(data_serialized), b.send_msg_idx[target]) b.send_msg_idx[target] += 1 sock.shutdown(2) sock.close() b.data_awaiting[target].append(data_header + data_serialized) data_out = a.receive() assert data_out == data_in a.shutdown(); b.shutdown()
def test_ShutdownClientServer(): a = Socket() b = Socket() a.listen(31415) b.connect(31415) b.shutdown() a.shutdown() assert threading.active_count() <= 1
def test_SendToSingleClient(data_in): a = Socket() b = Socket() a.listen() b.connect(a.port) a.send(data_in) data_out = b.receive() assert data_in == data_out a.shutdown(); b.shutdown()
def test_SendToServer(data_in): a = Socket() b = Socket() a.listen() b.connect(a.port) b.send(data_in) data_out = a.receive() assert data_in == data_out b.shutdown(); a.shutdown()
def test_compressionAndSecure(data_in): a = Socket(compress=True, encrypt=True) b = Socket(compress=True, encrypt=True) a.listen() b.connect(a.port) b.send(data_in) data_out = a.receive() assert data_out == data_in a.shutdown(); b.shutdown()
def test_Security(data_in): a = Socket(encrypt=True) b = Socket(encrypt=True) a.listen() b.connect(a.port) b.send(data_in) data_out = a.receive() assert data_out == data_in a.shutdown(); b.shutdown()
def test_SendMultipleData(data_in1, data_in2): a = Socket() b = Socket() a.listen() b.connect(a.port) b.send(data_in1) b.send(data_in2) data_out1, data_out2 = a.receive(), a.receive() assert data_in1 == data_out1 assert data_in2 == data_out2 a.shutdown(); b.shutdown()
def test_SendMultipleData(): a = Socket() b = Socket() 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.receive() assert x == data_out a.shutdown(); b.shutdown()
def test_CreateTwoServersBackToBack(): a = Socket() b = Socket() c = Socket() a.listen() a.shutdown() b.listen(a.port) c.connect(b.port) c.send(data[0]) data_out = b.receive() assert data[0] == data_out a.shutdown(); b.shutdown(); c.shutdown()
def test_ShutdownMultiple(): a = Socket() b = Socket() c = Socket() a.listen(27182) b.connect(27182) c.connect(27182) c.shutdown() b.shutdown() a.shutdown() assert threading.active_count() <= 1
def test_SendToAllClients(data_in): # Testing broadcast a = Socket() b = Socket() c = Socket() a.listen() b.connect(a.port) c.connect(a.port) a.send(data_in) data_out1, data_out2 = b.receive(), c.receive() assert data_in == data_out1 == data_out2 a.shutdown(); b.shutdown(); c.shutdown()
def test_SendToAllServers(data_in): # Testing multiple connection sending by a client a = Socket() b = Socket() c = Socket() a.listen() b.listen() c.connect(a.port) c.connect(b.port) c.send(data_in) data_out1, data_out2 = a.receive(), b.receive() assert data_in == data_out1 assert data_in == data_out2 a.shutdown(); b.shutdown(); c.shutdown()
def test_ShutdownSimple(): a = Socket() a.shutdown() assert threading.active_count() <= 1