From 83635845b6e41aa999fd15eb30cdbab286a49081 Mon Sep 17 00:00:00 2001 From: Jack Kingsman Date: Wed, 11 Mar 2026 19:32:54 -0700 Subject: [PATCH] Don't sleep in the exception handler --- app/radio_sync.py | 1 - tests/test_radio_sync.py | 10 +++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/app/radio_sync.py b/app/radio_sync.py index 444a6a1..8861b12 100644 --- a/app/radio_sync.py +++ b/app/radio_sync.py @@ -604,7 +604,6 @@ async def _periodic_advert_loop(): break except Exception as e: logger.error("Error in periodic advertisement loop: %s", e, exc_info=True) - await asyncio.sleep(ADVERT_CHECK_INTERVAL) def start_periodic_advert(): diff --git a/tests/test_radio_sync.py b/tests/test_radio_sync.py index 6066953..aa4f44d 100644 --- a/tests/test_radio_sync.py +++ b/tests/test_radio_sync.py @@ -1326,10 +1326,10 @@ class TestPeriodicAdvertLoopRaces: is caught by the outer except — loop survives and continues.""" rm, _mc = _make_connected_manager() _disconnect_on_acquire(rm) - # Advert loop: sleep first, then work. Sleep 1 (loop top) passes, - # work hits RadioDisconnectedError, error handler does sleep 2 (passes), - # next iteration sleep 3 cancels cleanly via except CancelledError. - mock_sleep, sleep_calls = _sleep_controller(cancel_after=3) + # Advert loop: sleep first, then work. Sleep 1 (loop top) passes, + # work hits RadioDisconnectedError, next iteration sleep 2 cancels + # cleanly via except CancelledError without an extra backoff sleep. + mock_sleep, sleep_calls = _sleep_controller(cancel_after=2) with ( patch("app.radio_sync.radio_manager", rm), @@ -1339,7 +1339,7 @@ class TestPeriodicAdvertLoopRaces: await _periodic_advert_loop() mock_advert.assert_not_called() - assert len(sleep_calls) == 3 + assert len(sleep_calls) == 2 @pytest.mark.asyncio async def test_busy_lock_skips_iteration(self):