mirror of
https://github.com/home-assistant/core.git
synced 2026-10-06 14:29:21 -04:00
Wait for the recording thread in Assist saved audio test (#183692)
This commit is contained in:
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user