nasa / fprime

F´ - A flight software and embedded systems framework
https://fprime.jpl.nasa.gov
Apache License 2.0
10.05k stars 1.3k forks source link

Integration Test API: Better Timeout implementation #2645

Open LeStarch opened 6 months ago

LeStarch commented 6 months ago

Presently timeouts are using the signal library and throw an exception to end the search. This timeout behavior can be modified very easily by changing the __search_test_history method. All searches use this method to accomplish scoping, logging and history substitution. Changing the timeout to something like below would be better.

# in IntegrationTestAPI's __search_test_history method on ~line 912 of api.py
if timeout:
    self.__log(name + " now awaiting for at most {} s.".format(timeout))
    end_time = time.time() + timeout
    while True:
        new_items = history.retrieve_new()
        for item in new_items:
            if searcher.incremental_search(item):
                return searcher.get_return_value()
        if time.time() >= end_time:
            msg = name + " timed out and ended unsuccessfully."
            self.__log(msg, TestLogger.YELLOW)
            break
        time.sleep(0.1)
else:
    self.__log(name + " ended unsuccessfully.", TestLogger.YELLOW)
return searcher.get_return_value()

NOTE: The above code hasn't been tested and may have issues if the system time changes: time.time().