@@ -423,27 +423,9 @@ async def test_keep_alive_task_canceled_on_connection_lost(local_channel: LocalC
423423
424424async def test_keep_alive_ping_loop_executes_periodically (local_channel : LocalChannel , mock_loop : Mock ) -> None :
425425 """Test that the ping loop continues to execute periodically while connected."""
426- ping_count = 0
427-
428- # Mock the _ping method to track calls
429- original_ping = local_channel ._ping
430-
431- async def mock_ping () -> None :
432- nonlocal ping_count
433- ping_count += 1
434- await original_ping ()
435-
436- setattr (local_channel , "_ping" , mock_ping )
437-
438426 await local_channel .connect ()
439427
440- # Wait for multiple ping intervals
441- # _PING_INTERVAL is 10 seconds, so we'll wait a bit longer to see multiple pings
442- # We'll use a shorter wait in the test and manually advance time
443- await asyncio .sleep (0.1 ) # Give the task time to start
444-
445- # Since we can't easily fast-forward time in this test setup,
446- # we'll just verify the task is running
428+ # Verify the task is running and connected
447429 assert local_channel ._keep_alive_task is not None
448430 assert not local_channel ._keep_alive_task .done ()
449431 assert local_channel ._is_connected
@@ -453,6 +435,8 @@ async def test_keep_alive_ping_exceptions_handled_gracefully(
453435 local_channel : LocalChannel , mock_loop : Mock , caplog : pytest .LogCaptureFixture
454436) -> None :
455437 """Test that exceptions in the ping loop are handled gracefully without stopping the loop."""
438+ from roborock .devices .local_channel import _PING_INTERVAL
439+
456440 # Set log level to capture DEBUG messages
457441 caplog .set_level ("DEBUG" )
458442
@@ -468,8 +452,8 @@ async def mock_ping() -> None:
468452 original_sleep = asyncio .sleep
469453
470454 async def mock_sleep (delay : float ) -> None :
471- # Only sleep briefly for test speed
472- if delay > 1 :
455+ # Only sleep briefly for test speed when waiting for ping interval
456+ if delay >= _PING_INTERVAL :
473457 await original_sleep (0.01 )
474458 else :
475459 await original_sleep (delay )
0 commit comments