From e31385f1abf0b2892d2a46530a3515627e32f936 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Thu, 22 Feb 2024 00:08:10 -0600 Subject: [PATCH] athenad: fix test timeouts and comments (#31540) * these pass in 0.5s since server sends ping on connect * comments * unused * fix * fix these too * check end_event while uploading, throw abort exception if we need to shut down/restart * Revert "check end_event while uploading, throw abort exception if we need to shut down/restart" This reverts commit f0b822fca98cd8e2b3d4d6d5ede6b512d3ed3ec0. * more tol for lte connection old-commit-hash: c0e172e0c08a7e09feb27905b0705ed3df992f21 --- selfdrive/athena/athenad.py | 3 +++ selfdrive/athena/tests/test_athenad_ping.py | 8 +++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/selfdrive/athena/athenad.py b/selfdrive/athena/athenad.py index 833bf841f5..ca3a1bafbb 100755 --- a/selfdrive/athena/athenad.py +++ b/selfdrive/athena/athenad.py @@ -746,6 +746,9 @@ def ws_manage(ws: WebSocket, end_event: threading.Event) -> None: onroad_prev = onroad if sock is not None: + # While not sending data, onroad, we can expect to time out in 7 + (7 * 2) = 21s + # offroad, we can expect to time out in 30 + (10 * 3) = 60s + # FIXME: TCP_USER_TIMEOUT is effectively 2x for some reason (32s), so it's mostly unused sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_USER_TIMEOUT, 16000 if onroad else 0) sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPIDLE, 7 if onroad else 30) sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPINTVL, 7 if onroad else 10) diff --git a/selfdrive/athena/tests/test_athenad_ping.py b/selfdrive/athena/tests/test_athenad_ping.py index 49bd5f1142..7f32f60cb4 100755 --- a/selfdrive/athena/tests/test_athenad_ping.py +++ b/selfdrive/athena/tests/test_athenad_ping.py @@ -12,6 +12,8 @@ from openpilot.selfdrive.athena import athenad from openpilot.selfdrive.manager.helpers import write_onroad_params from openpilot.system.hardware import TICI +TIMEOUT_TOLERANCE = 20 # seconds + def wifi_radio(on: bool) -> None: if not TICI: @@ -63,7 +65,7 @@ class TestAthenadPing(unittest.TestCase): mock_create_connection.assert_called_once() mock_create_connection.reset_mock() - # check normal behaviour + # check normal behaviour, server pings on connection with self.subTest("Wi-Fi: receives ping"), Timeout(70, "no ping received"): while not self._received_ping(): time.sleep(0.1) @@ -92,12 +94,12 @@ class TestAthenadPing(unittest.TestCase): @unittest.skipIf(not TICI, "only run on desk") def test_offroad(self) -> None: write_onroad_params(False, self.params) - self.assertTimeout(100) # expect approx 90s + self.assertTimeout(60 + TIMEOUT_TOLERANCE) # based using TCP keepalive settings @unittest.skipIf(not TICI, "only run on desk") def test_onroad(self) -> None: write_onroad_params(True, self.params) - self.assertTimeout(30) # expect 20-30s + self.assertTimeout(21 + TIMEOUT_TOLERANCE) if __name__ == "__main__":