mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Avoid race condition with UDP voice server starting in ESPHome (#111644)
* Avoid race condition with UDP server starting * Fix test
This commit is contained in:
parent
00d11ff68e
commit
890e651bdd
@ -160,10 +160,10 @@ class VoiceAssistantUDPServer(asyncio.DatagramProtocol):
|
|||||||
|
|
||||||
async def _iterate_packets(self) -> AsyncIterable[bytes]:
|
async def _iterate_packets(self) -> AsyncIterable[bytes]:
|
||||||
"""Iterate over incoming packets."""
|
"""Iterate over incoming packets."""
|
||||||
if not self.is_running:
|
|
||||||
raise RuntimeError("Not running")
|
|
||||||
|
|
||||||
while data := await self.queue.get():
|
while data := await self.queue.get():
|
||||||
|
if not self.is_running:
|
||||||
|
break
|
||||||
|
|
||||||
yield data
|
yield data
|
||||||
|
|
||||||
def _event_callback(self, event: PipelineEvent) -> None:
|
def _event_callback(self, event: PipelineEvent) -> None:
|
||||||
|
@ -224,9 +224,13 @@ async def test_udp_server_queue(
|
|||||||
|
|
||||||
voice_assistant_udp_server_v1.close()
|
voice_assistant_udp_server_v1.close()
|
||||||
|
|
||||||
with pytest.raises(RuntimeError):
|
# Stopping the UDP server should cause _iterate_packets to break out
|
||||||
async for data in voice_assistant_udp_server_v1._iterate_packets():
|
# immediately without yielding any data.
|
||||||
assert data == bytes(1024)
|
has_data = False
|
||||||
|
async for _data in voice_assistant_udp_server_v1._iterate_packets():
|
||||||
|
has_data = True
|
||||||
|
|
||||||
|
assert not has_data, "Server was stopped"
|
||||||
|
|
||||||
|
|
||||||
async def test_error_calls_handle_finished(
|
async def test_error_calls_handle_finished(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user