diff --git a/selfdrive/athena/athenad.py b/selfdrive/athena/athenad.py index 2ef7d56cc1..d8b495e552 100755 --- a/selfdrive/athena/athenad.py +++ b/selfdrive/athena/athenad.py @@ -311,9 +311,8 @@ def get_logs_to_send_sorted(): # assume send failed and we lost the response if sent more than one hour ago if not time_sent or curr_time - time_sent > 3600: logs.append(log_entry) - # return logs in order they should be sent # excluding most recent (active) log file - return sorted(logs[:-1]) + return sorted(logs)[:-1] def log_handler(end_event): @@ -332,7 +331,7 @@ def log_handler(end_event): # send one log curr_log = None if len(log_files) > 0: - log_entry = log_files.pop() + log_entry = log_files.pop() # newest log file cloudlog.debug(f"athena.log_handler.forward_request {log_entry}") try: curr_time = int(time.time()) diff --git a/selfdrive/athena/tests/test_athenad.py b/selfdrive/athena/tests/test_athenad.py index 4002f60d19..be6c631a0c 100755 --- a/selfdrive/athena/tests/test_athenad.py +++ b/selfdrive/athena/tests/test_athenad.py @@ -14,6 +14,7 @@ from unittest import mock from websocket import ABNF from websocket._exceptions import WebSocketConnectionClosedException +from selfdrive import swaglog from selfdrive.athena import athenad from selfdrive.athena.athenad import dispatcher from selfdrive.athena.tests.helpers import MockWebsocket, MockParams, MockApi, EchoSocket, with_http_server @@ -24,6 +25,7 @@ class TestAthenadMethods(unittest.TestCase): def setUpClass(cls): cls.SOCKET_PORT = 45454 athenad.ROOT = tempfile.mkdtemp() + athenad.SWAGLOG_DIR = swaglog.SWAGLOG_DIR = tempfile.mkdtemp() athenad.Params = MockParams athenad.Api = MockApi athenad.LOCAL_PORT_WHITELIST = set([cls.SOCKET_PORT]) @@ -204,5 +206,16 @@ class TestAthenadMethods(unittest.TestCase): end_event.set() thread.join() + def test_get_logs_to_send_sorted(self): + fl = list() + for i in range(10): + fn = os.path.join(swaglog.SWAGLOG_DIR, f'swaglog.{i:010}') + Path(fn).touch() + fl.append(os.path.basename(fn)) + + # ensure the list is all logs except most recent + sl = athenad.get_logs_to_send_sorted() + self.assertListEqual(sl, fl[:-1]) + if __name__ == '__main__': unittest.main()