Beispiel #1
0
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()
Beispiel #2
0
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()
Beispiel #3
0
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()
Beispiel #4
0
            logging.debug("%s packet(s) still waiting in queue",
                          inputQueue.qsize())

            bwPacket = Decoder.decode(data[0])
            inputQueue.task_done()

            if bwPacket is None:
                continue

            bwPacket.printInfo()
            misc.addClientDataToPacket(bwPacket, bwConfig)

            for sendCnt in range(
                    bwConfig.get("client", "sendTries", default="3")):
                bwClient.transmit(str(bwPacket))
                if bwClient.receive() == "[ack]":
                    logging.debug("ack ok")
                    break
                sendDelay = bwConfig.get("client", "sendDelay", default="3")
                logging.warning("cannot send packet - sleep %d seconds",
                                sendDelay)
                time.sleep(sendDelay)

        else:
            if args.test:
                break
            time.sleep(0.1)  # reduce cpu load (wait 100ms)
            # in worst case a packet have to wait 100ms until it will be processed

except KeyboardInterrupt:  # pragma: no cover
    logging.warning("Keyboard interrupt")