コード例 #1
0
def test_process_tlms():
    logger.debug(os.environ.get('PYTEST_CURRENT_TEST').split(':')[-1].split(' ')[0])
    reporter = AvisoRestReporter(Config(**config), receiver())
    metrics = reporter.process_tlms()
    assert len(metrics) == 1
    assert len(metrics[0].get("metrics")) == 3
    assert len(list(filter(lambda m: m["m_value"] == 4, metrics[0].get("metrics")))) == 1
コード例 #2
0
ファイル: test_time_collector.py プロジェクト: raghu330/aviso
def test_calling_timer():
    logger.debug(
        os.environ.get('PYTEST_CURRENT_TEST').split(':')[-1].split(' ')[0])

    # create the collector
    timer = TimeCollector(Config(**collector_config))

    assert timer(take_some_time)
    timer(take_some_time, args=0.1)
    timer(take_some_time, args=[0.1])
    assert not timer(take_some_time, args=(0.1, True, False))
    timer(take_some_time, args=[0.1, False])
    timer(take_some_time, kwargs={"flag": True})
    timer(take_some_time, args=0.2, kwargs={"flag": True})
コード例 #3
0
ファイル: test_receiver.py プロジェクト: raghu330/aviso
def test_send_message():
    logger.debug(
        os.environ.get('PYTEST_CURRENT_TEST').split(':')[-1].split(' ')[0])

    # create the UDP server
    receiver = Receiver()
    udp_server = UdpServer(upd_server_config, receiver)
    udp_server.start()

    # send 2 test message
    byte_message = json.dumps(test_message).encode()
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    assert s.sendto(byte_message,
                    (upd_server_config["host"], upd_server_config["port"]))
    assert s.sendto(byte_message,
                    (upd_server_config["host"], upd_server_config["port"]))
    s.close()

    time.sleep(1)
    # verify they are received
    assert len(receiver.incoming_tlms(test_message["telemetry_type"])) == 2

    # send message of different type
    test_message2 = test_message.copy()
    test_message2["telemetry_type"] = "type2"
    byte_message = json.dumps(test_message2).encode()
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    assert s.sendto(byte_message,
                    (upd_server_config["host"], upd_server_config["port"]))
    s.close()

    time.sleep(1)
    # verify it's received properly
    assert len(receiver.incoming_tlms(test_message["telemetry_type"])) == 2
    assert len(receiver.incoming_tlms(test_message2["telemetry_type"])) == 1

    # send a wrong message of same type
    test_message2.pop("component_name")
    byte_message = json.dumps(test_message2).encode()
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    assert s.sendto(byte_message,
                    (upd_server_config["host"], upd_server_config["port"]))
    s.close()

    time.sleep(1)
    # verify it's NOT received properly
    assert len(receiver.incoming_tlms(test_message["telemetry_type"])) == 2
    assert len(receiver.incoming_tlms(test_message2["telemetry_type"])) == 1

    udp_server.stop()
コード例 #4
0
ファイル: test_etcd_reporter.py プロジェクト: raghu330/aviso
def test_process_tlms():
    logger.debug(
        os.environ.get('PYTEST_CURRENT_TEST').split(':')[-1].split(' ')[0])
    reporter = EtcdReporter(Config(**config))
    metrics = reporter.process_tlms()
    assert len(metrics) == 3
    store_size = list(filter(lambda m: m["name"] == "etcd_store_size",
                             metrics))[0]
    assert len(store_size["metrics"]) == 3
    status = list(filter(lambda m: m["name"] == "etcd_cluster_status",
                         metrics))[0]
    assert len(status["metrics"]) == 1
    keys = list(filter(lambda m: m["name"] == "etcd_total_keys", metrics))[0]
    assert len(keys["metrics"]) == 1
コード例 #5
0
ファイル: test_time_collector.py プロジェクト: raghu330/aviso
 def process_message(self, message):
     logger.debug(f"Message received: {message}")
     assert message.get("telemetry_type") == collector_config.get(
         "telemetry_type")
     assert message.get("component_name") == collector_config.get(
         "transmitter").get("component_name")
     assert message.get("hostname")
     assert message.get("time")
     assert message.get("telemetry")
     assert message.get("telemetry").get(
         f"{collector_config.get('telemetry_type')}_avg") > 0
     assert message.get("telemetry").get(
         f"{collector_config.get('telemetry_type')}_counter") == 10
     global received
     received = True
コード例 #6
0
ファイル: test_time_collector.py プロジェクト: raghu330/aviso
def test_measure_time():
    logger.debug(
        os.environ.get('PYTEST_CURRENT_TEST').split(':')[-1].split(' ')[0])

    # create the UDP server with mock ServiceRegister
    udp_server = UdpServer(upd_server_config, ReceiverMock())
    udp_server.start()

    # create the collector
    timer = TimeCollector(Config(**collector_config))

    # call the function
    for i in range(10):
        timer(take_some_time, args=0.1)

    # wait to receive it
    sleep(2)
    assert received
    udp_server.stop()
コード例 #7
0
ファイル: test_etcd_reporter.py プロジェクト: raghu330/aviso
def test_run_reporter():
    logger.debug(
        os.environ.get('PYTEST_CURRENT_TEST').split(':')[-1].split(' ')[0])
    reporter = EtcdReporter(Config(**config))
    reporter.run()