From 25488243e26e6147a3ead328229c8f45fc68121b Mon Sep 17 00:00:00 2001 From: Erwin Douna Date: Wed, 30 Sep 2026 09:58:50 +0200 Subject: [PATCH] Wait for the recording thread in Assist saved audio test (#183692) --- tests/components/assist_pipeline/test_init.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/tests/components/assist_pipeline/test_init.py b/tests/components/assist_pipeline/test_init.py index 962a7204bddc..52f995e6c0d5 100644 --- a/tests/components/assist_pipeline/test_init.py +++ b/tests/components/assist_pipeline/test_init.py @@ -1,10 +1,10 @@ """Test Voice Assistant init.""" -import asyncio from collections.abc import Generator import itertools as it from pathlib import Path import tempfile +import threading import time from unittest.mock import Mock, patch import wave @@ -665,9 +665,11 @@ async def test_pipeline_saved_audio_empty_queue( with wave.open(str(wav_path), "rb") as wav_file: assert wav_file.getnframes() == 0 + recording_thread_done = threading.Event() + async def audio_data(): - # Force timeout in _pipeline_debug_recording_thread_proc - await asyncio.sleep(1) + # Keep the stream open until the recording thread has timed out + await hass.async_add_executor_job(recording_thread_done.wait) yield b"not used" # Wrap original function to time out immediately @@ -681,9 +683,12 @@ async def test_pipeline_saved_audio_empty_queue( while queue.empty(): time.sleep(0.01) - _pipeline_debug_recording_thread_proc( - run_recording_dir, queue, message_timeout=0 - ) + try: + _pipeline_debug_recording_thread_proc( + run_recording_dir, queue, message_timeout=0 + ) + finally: + recording_thread_done.set() with patch( "homeassistant.components.assist_pipeline.run._pipeline_debug_recording_thread_proc",