Exemple #1
0
def get_upcoming_event(
    test_api: IntegrationTestAPI,
    search_filter: predicates.predicate,
    start_time="NOW",
    timeout: float = 5,
) -> EventData:
    """
    Returns the next event matching the given search filter that occurs after
    this is called. Times out after the given amount if no matching new events
    are found.

    :param test_api: An API instance that will be called to find the next event
    :param search_filter: A predicate each found event is tested against; if
        the event doesn't test "True" against this, we ignore it and keep
        searching
    :param start_time: An optional index or predicate to specify the earliest
        event time to search for
    :param timeout: The maximum time (in seconds) to wait for an event

    :return: The first "EventData" found that passes the filter, or "None" if no
        such event is found within time
    """
    event_filter = predicates.satisfies_all(
        [search_filter, predicates.event_predicate()])
    # Test API only takes integer timeouts
    return test_api.find_history_item(event_filter,
                                      test_api.get_event_test_history(),
                                      start_time, int(timeout))
Exemple #2
0
    def test_get_event_pred(self):
        pred = predicates.event_predicate()
        result = self.api.get_event_pred(pred)
        assert pred == result, "should return when channel is already event_pred"

        message = self.get_severity_event("FATAL")
        pred = self.api.get_event_pred(message.get_id(), message.get_args(),
                                       message.get_severity())
        assert pred(
            message), "predicate should return true when fields are specified"
    def test_event_predicates(self):
        args1_def = [("name", "string", StringType()), ("age", "int", I32Type())]
        temp1 = EventTemplate(
            1,
            "Test Msg 1",
            "Predicate Tester",
            args1_def,
            EventSeverity.ACTIVITY_LO,
            "",
        )
        args1 = (StringType("John"), I32Type(35))
        msg1 = EventData(args1, TimeType(), temp1)
        args2_def = [
            ("description", "string", StringType()),
            ("count", "int", I32Type()),
        ]
        temp2 = EventTemplate(
            2,
            "Test Msg 2",
            "Predicate Tester",
            args2_def,
            EventSeverity.ACTIVITY_HI,
            "",
        )
        args2 = (StringType("Dozen"), I32Type(12))
        msg2 = EventData(args2, TimeType(), temp2)

        pred = predicates.event_predicate()
        assert pred(
            msg1
        ), "If no fields are specified an EventData object should return True"
        assert pred(
            msg2
        ), "If no fields are specified an EventData object should return True"
        assert not pred(
            "diff object"
        ), "Anything that's not an EventData object should be False"
        assert not pred(5), "Anything that's not a EventData object should be False"
        self.check_str(pred)

        id_pred = predicates.equal_to(1)
        pred = predicates.event_predicate(id_pred=id_pred)
        assert pred(msg1), "This predicate on the ID 1 should return True"
        assert not pred(msg2), "This predicate on the ID 2 should return False"
        self.check_str(pred)

        args_pred = predicates.args_predicate([None, None])
        pred = predicates.event_predicate(args_pred=args_pred)
        assert pred(
            msg1
        ), "This predicate should return True, as it expects an event with 2 args"
        assert pred(
            msg2
        ), "This predicate should return True, as it expects an event with 2 args"
        self.check_str(pred)

        args_pred = predicates.args_predicate(["John", 35])
        pred = predicates.event_predicate(args_pred=args_pred)
        assert pred(
            msg1
        ), "This predicate should return True as msg1 has args (str John, int32 35)"
        assert not pred(
            msg2
        ), "This predicate should return False as msg2 has args (str Dozen, int32 12)"
        self.check_str(pred)

        severity_pred = predicates.equal_to(EventSeverity.ACTIVITY_LO)
        pred = predicates.event_predicate(severity_pred=severity_pred)
        assert severity_pred(msg1.get_severity())
        assert pred(
            msg1
        ), "This predicate should return True as msg1 has an ACTIVITY_LO severity"
        assert not pred(
            msg2
        ), "This predicate should return False as msg2 has an ACTIVITY_HI severity"
        self.check_str(pred)

        time_pred = predicates.equal_to(0)
        pred = predicates.event_predicate(time_pred=time_pred)
        assert pred(msg1), "This predicate on the time 0 should return True"
        assert pred(msg2), "This predicate on the time 0 should return True"
        self.check_str(pred)

        pred = predicates.event_predicate(id_pred, args_pred, severity_pred, time_pred)
        assert pred(msg1), "Specifying all fields should return True for msg1"
        assert not pred(msg2), "Specifying all fields should return False for msg2"
        self.check_str(pred)