def test_clientMultiConnect(getClient, getRunningServer):
    """!Connect with 2 clients to the server"""
    assert getClient.connect()
    testClient2 = TCPClient()
    assert testClient2.connect()
    time.sleep(0.1)  # wait for all clients connected
    # check connected clients
    assert getRunningServer.countClientsConnected() == 2
    # disconnect all
    assert getClient.disconnect()
    assert testClient2.disconnect()
def sendThread():
    client = TCPClient()
    client.connect()
    time.sleep(0.1)
    for i in range(100):
        # actually this string is 324 bytes long
        client.transmit(
            "HigLoadTestString-HigLoadTestString-HigLoadTestString-HigLoadTestString-HigLoadTestString-HigLoadTestString-"
            "HigLoadTestString-HigLoadTestString-HigLoadTestString-HigLoadTestString-HigLoadTestString-HigLoadTestString-"
            "HigLoadTestString-HigLoadTestString-HigLoadTestString-HigLoadTestString-HigLoadTestString-HigLoadTestString-"
        )
        if not client.receive() == "[ack]":
            logging.error("missing [ACK]")

    time.sleep(0.1)
    client.disconnect()
Exemple #3
0
            exit(1)

        inputSource.start()
    else:
        logging.warning("STARTING TESTMODE!")
        logging.debug("reading testdata from file")
        testFile = open("test/testdata.list", mode="r", encoding="utf-8")
        for testData in testFile:
            if (len(testData.rstrip(' \t\n\r')) > 1) and ("#"
                                                          not in testData[0]):
                logging.info("Testdata: %s", testData.rstrip(' \t\n\r'))
                inputQueue.put_nowait(
                    (testData.rstrip(' \t\n\r'), time.time()))
        logging.debug("finished reading testdata")

    bwClient = TCPClient()
    bwClient.connect(ip, port)
    while 1:

        if not bwClient.isConnected:
            reconnectDelay = bwConfig.get("client",
                                          "reconnectDelay",
                                          default="3")
            logging.warning("connection to server lost - sleep %d seconds",
                            reconnectDelay)
            time.sleep(reconnectDelay)
            bwClient.connect(ip, port)

        elif not inputQueue.empty():
            data = inputQueue.get()
            logging.info("get data from queue (waited %0.3f sec.)",
def getClient():
    """!Build and serve a TCPCLient"""
    return TCPClient()
def test_serverGetOutput(getRunningServer):
    """!Send data to server with 2 clients, check '[ack]' and data on server queue"""
    # connect all
    testClient1 = TCPClient()
    assert testClient1.connect()
    testClient2 = TCPClient()
    assert testClient2.connect()
    # send all
    assert testClient1.transmit("test1")
    time.sleep(0.1)  # wait for recv to prevent fail of false order
    assert testClient2.transmit("test2")
    # recv all
    assert testClient1.receive() == "[ack]"
    assert testClient2.receive() == "[ack]"
    # _check server output data
    assert getRunningServer._alarmQueue.qsize() == 2
    assert getRunningServer._alarmQueue.get(True, 1)[1] == "test1"
    assert getRunningServer._alarmQueue.get(True, 1)[1] == "test2"
    assert getRunningServer._alarmQueue.qsize(
    ) == 0  # Last _check must be None
    # disconnect all
    assert testClient1.disconnect()
    assert testClient2.disconnect()
def test_clientMultiCommunicate(getServer):
    """!Try to send data to the server with 3 clients and check on '[ack]'"""
    # connect all
    testClient1 = TCPClient()
    assert testClient1.connect()
    testClient2 = TCPClient()
    assert testClient2.connect()
    testClient3 = TCPClient()
    assert testClient3.connect()
    # send all
    assert testClient1.transmit("test")
    assert testClient2.transmit("test")
    assert testClient3.transmit("test")
    # recv all
    assert testClient3.receive() == "[ack]"
    assert testClient2.receive() == "[ack]"
    assert testClient1.receive() == "[ack]"
    # check server msg queue
    assert getRunningServer._alarmQueue.qsize() == 3
    # disconnect all
    assert testClient1.disconnect()
    assert testClient2.disconnect()
    assert testClient3.disconnect()