Try to fix confirm and interrupt

This commit is contained in:
Xin Wang
2026-08-04 10:19:59 +08:00
parent caa2ff65fa
commit da828aca41
5 changed files with 96 additions and 46 deletions

View File

@@ -1,5 +1,6 @@
from __future__ import annotations
import asyncio
import unittest
from types import SimpleNamespace
from unittest.mock import AsyncMock, patch
@@ -10,7 +11,7 @@ from pipecat.frames.frames import (
OutputTransportMessageUrgentFrame,
)
from services.pipecat.pipeline_events import bind_cascade_pipeline_events
from services.pipecat.pipeline import _wait_for_interrupted_output
from services.pipecat.pipeline import _wait_for_output_stop
class _EventSource:
@@ -81,31 +82,25 @@ class _Brain:
class PipelineEventTest(unittest.IsolatedAsyncioTestCase):
async def test_interrupted_output_waits_for_flush_and_stop(self):
async def test_interrupted_output_waits_for_transport_stop(self):
events = []
async def wait_until_stopped():
events.append("stopped")
worker = SimpleNamespace(
flush_pipeline=AsyncMock(
side_effect=lambda **_kwargs: events.append("flush") or True
await _wait_for_output_stop(wait_until_stopped)
self.assertEqual(events, ["stopped"])
async def test_interrupted_output_rejects_stop_timeout(self):
async def wait_forever():
await asyncio.Event().wait()
with self.assertRaisesRegex(RuntimeError, "语音停止超时"):
await _wait_for_output_stop(
wait_forever,
timeout_seconds=0.001,
)
)
await _wait_for_interrupted_output(
worker,
wait_until_stopped=wait_until_stopped,
)
self.assertEqual(events, ["flush", "stopped"])
worker.flush_pipeline.assert_awaited_once_with(timeout=2.0)
async def test_interrupted_output_rejects_flush_timeout(self):
worker = SimpleNamespace(flush_pipeline=AsyncMock(return_value=False))
with self.assertRaisesRegex(RuntimeError, "中断帧"):
await _wait_for_interrupted_output(worker)
async def test_greeting_keeps_playback_timestamp_until_client_ready(self):
transport = _EventSource()