From d99a7e2825440fece3babc3f5a14007b14761003 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 17 Feb 2024 01:24:21 -0600 Subject: [PATCH] Fix race in wyoming test (#110766) reverts #110751 and replaces it with a change to wait for the assist_pipeline.async_pipeline_from_audio_stream to be called which will actually solve the problem and unblock #110743 --- tests/components/wyoming/test_satellite.py | 33 +++++++++++----------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/tests/components/wyoming/test_satellite.py b/tests/components/wyoming/test_satellite.py index 81f5cd52e7a..f568f7b6975 100644 --- a/tests/components/wyoming/test_satellite.py +++ b/tests/components/wyoming/test_satellite.py @@ -603,25 +603,25 @@ async def test_satellite_error_during_pipeline(hass: HomeAssistant) -> None: ).event(), ] # no audio chunks after RunPipeline - client_created_event = asyncio.Event() - mock_client = SatelliteAsyncTcpClient(events) + pipeline_event = asyncio.Event() - def _async_make_tcp_client(*args: Any, **kwargs: Any) -> SatelliteAsyncTcpClient: - client_created_event.set() - return mock_client + def _async_pipeline_from_audio_stream(*args: Any, **kwargs: Any) -> None: + pipeline_event.set() with patch( "homeassistant.components.wyoming.data.load_wyoming_info", return_value=SATELLITE_INFO, ), patch( "homeassistant.components.wyoming.satellite.AsyncTcpClient", - _async_make_tcp_client, - ), patch( + SatelliteAsyncTcpClient(events), + ) as mock_client, patch( "homeassistant.components.wyoming.satellite.assist_pipeline.async_pipeline_from_audio_stream", + wraps=_async_pipeline_from_audio_stream, ) as mock_run_pipeline: await setup_config_entry(hass) + async with asyncio.timeout(1): - await client_created_event.wait() + await pipeline_event.wait() await mock_client.connect_event.wait() await mock_client.run_satellite_event.wait() @@ -658,22 +658,20 @@ async def test_tts_not_wav(hass: HomeAssistant) -> None: events = [ RunPipeline(start_stage=PipelineStage.TTS, end_stage=PipelineStage.TTS).event(), ] + pipeline_event = asyncio.Event() - client_created_event = asyncio.Event() - mock_client = SatelliteAsyncTcpClient(events) - - def _async_make_tcp_client(*args: Any, **kwargs: Any) -> SatelliteAsyncTcpClient: - client_created_event.set() - return mock_client + def _async_pipeline_from_audio_stream(*args: Any, **kwargs: Any) -> None: + pipeline_event.set() with patch( "homeassistant.components.wyoming.data.load_wyoming_info", return_value=SATELLITE_INFO, ), patch( "homeassistant.components.wyoming.satellite.AsyncTcpClient", - _async_make_tcp_client, - ), patch( + SatelliteAsyncTcpClient(events), + ) as mock_client, patch( "homeassistant.components.wyoming.satellite.assist_pipeline.async_pipeline_from_audio_stream", + wraps=_async_pipeline_from_audio_stream, ) as mock_run_pipeline, patch( "homeassistant.components.wyoming.satellite.tts.async_get_media_source_audio", return_value=("mp3", bytes(1)), @@ -682,8 +680,9 @@ async def test_tts_not_wav(hass: HomeAssistant) -> None: _stream_tts, ): entry = await setup_config_entry(hass) + async with asyncio.timeout(1): - await client_created_event.wait() + await pipeline_event.wait() await mock_client.connect_event.wait() await mock_client.run_satellite_event.wait()