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
This commit is contained in:
J. Nick Koston 2024-02-17 01:24:21 -06:00 committed by GitHub
parent aa5695a859
commit d99a7e2825
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -603,25 +603,25 @@ async def test_satellite_error_during_pipeline(hass: HomeAssistant) -> None:
).event(), ).event(),
] # no audio chunks after RunPipeline ] # no audio chunks after RunPipeline
client_created_event = asyncio.Event() pipeline_event = asyncio.Event()
mock_client = SatelliteAsyncTcpClient(events)
def _async_make_tcp_client(*args: Any, **kwargs: Any) -> SatelliteAsyncTcpClient: def _async_pipeline_from_audio_stream(*args: Any, **kwargs: Any) -> None:
client_created_event.set() pipeline_event.set()
return mock_client
with patch( with patch(
"homeassistant.components.wyoming.data.load_wyoming_info", "homeassistant.components.wyoming.data.load_wyoming_info",
return_value=SATELLITE_INFO, return_value=SATELLITE_INFO,
), patch( ), patch(
"homeassistant.components.wyoming.satellite.AsyncTcpClient", "homeassistant.components.wyoming.satellite.AsyncTcpClient",
_async_make_tcp_client, SatelliteAsyncTcpClient(events),
), patch( ) as mock_client, patch(
"homeassistant.components.wyoming.satellite.assist_pipeline.async_pipeline_from_audio_stream", "homeassistant.components.wyoming.satellite.assist_pipeline.async_pipeline_from_audio_stream",
wraps=_async_pipeline_from_audio_stream,
) as mock_run_pipeline: ) as mock_run_pipeline:
await setup_config_entry(hass) await setup_config_entry(hass)
async with asyncio.timeout(1): async with asyncio.timeout(1):
await client_created_event.wait() await pipeline_event.wait()
await mock_client.connect_event.wait() await mock_client.connect_event.wait()
await mock_client.run_satellite_event.wait() await mock_client.run_satellite_event.wait()
@ -658,22 +658,20 @@ async def test_tts_not_wav(hass: HomeAssistant) -> None:
events = [ events = [
RunPipeline(start_stage=PipelineStage.TTS, end_stage=PipelineStage.TTS).event(), RunPipeline(start_stage=PipelineStage.TTS, end_stage=PipelineStage.TTS).event(),
] ]
pipeline_event = asyncio.Event()
client_created_event = asyncio.Event() def _async_pipeline_from_audio_stream(*args: Any, **kwargs: Any) -> None:
mock_client = SatelliteAsyncTcpClient(events) pipeline_event.set()
def _async_make_tcp_client(*args: Any, **kwargs: Any) -> SatelliteAsyncTcpClient:
client_created_event.set()
return mock_client
with patch( with patch(
"homeassistant.components.wyoming.data.load_wyoming_info", "homeassistant.components.wyoming.data.load_wyoming_info",
return_value=SATELLITE_INFO, return_value=SATELLITE_INFO,
), patch( ), patch(
"homeassistant.components.wyoming.satellite.AsyncTcpClient", "homeassistant.components.wyoming.satellite.AsyncTcpClient",
_async_make_tcp_client, SatelliteAsyncTcpClient(events),
), patch( ) as mock_client, patch(
"homeassistant.components.wyoming.satellite.assist_pipeline.async_pipeline_from_audio_stream", "homeassistant.components.wyoming.satellite.assist_pipeline.async_pipeline_from_audio_stream",
wraps=_async_pipeline_from_audio_stream,
) as mock_run_pipeline, patch( ) as mock_run_pipeline, patch(
"homeassistant.components.wyoming.satellite.tts.async_get_media_source_audio", "homeassistant.components.wyoming.satellite.tts.async_get_media_source_audio",
return_value=("mp3", bytes(1)), return_value=("mp3", bytes(1)),
@ -682,8 +680,9 @@ async def test_tts_not_wav(hass: HomeAssistant) -> None:
_stream_tts, _stream_tts,
): ):
entry = await setup_config_entry(hass) entry = await setup_config_entry(hass)
async with asyncio.timeout(1): async with asyncio.timeout(1):
await client_created_event.wait() await pipeline_event.wait()
await mock_client.connect_event.wait() await mock_client.connect_event.wait()
await mock_client.run_satellite_event.wait() await mock_client.run_satellite_event.wait()