Ejemplo n.º 1
0
def test_perfcounters_correct_status_values():
    c = Perfcounters(logger)

    for _x in range(5):
        c.count("messages")

    for _x in range(10):
        c.count("events")

    for _x in range(10):
        c.count("connects")

    for _x in range(2):
        c.count("rule_tries")

    for column_name, column_value in zip([n for n, _d in c.status_columns()], c.get_status()):
        if column_name.startswith("status_average_") and column_name.endswith("_time"):
            counter_name = column_name.split("_")[-2]
            assert column_value == c._times.get(counter_name, 0.0)

        elif column_name.startswith("status_average_") and column_name.endswith("_rate"):
            counter_name = column_name.split("_")[-2]
            assert column_value == c._average_rates.get(counter_name, 0.0)

        elif column_name.startswith("status_") and column_name.endswith("_rate"):
            counter_name = column_name.split("_")[-2]
            assert column_value == c._rates.get(counter_name, 0.0)

        elif column_name.startswith("status_"):
            counter_name = "_".join(column_name.split("_")[1:])
            assert column_value == c._counters[counter_name], "Invalid value %r: %r" % (
                column_name, c._counters[counter_name])

        else:
            raise NotImplementedError()
Ejemplo n.º 2
0
def test_perfcounters_column_default_values():
    c = Perfcounters(logger)
    for column_name, default_value in c.status_columns():
        if column_name.startswith("status_average_") and column_name.endswith(
                "_time"):
            assert isinstance(default_value, float)
            assert default_value == 0.0

        elif column_name.startswith(
                "status_average_") and column_name.endswith("_rate"):
            assert isinstance(default_value, float)
            assert default_value == 0.0

        elif column_name.startswith("status_") and column_name.endswith(
                "_rate"):
            assert isinstance(default_value, float)
            assert default_value == 0.0

        elif column_name.startswith("status_"):
            assert isinstance(
                default_value,
                int), "Wrong column type %r: %s" % (column_name,
                                                    type(default_value))
            assert default_value == 0, "Wrong column default value %r: %d" % (
                column_name, default_value)
Ejemplo n.º 3
0
def test_perfcounters_columns_match_status_length():
    c = Perfcounters(logger)
    assert len(c.status_columns()) == len(c.get_status())