fix: manage WebRTC pipeline shutdown

This commit is contained in:
Xin Wang
2026-08-05 13:48:29 +08:00
parent 10bea48d72
commit 16156028c9
6 changed files with 253 additions and 9 deletions
@@ -1,5 +1,6 @@
from __future__ import annotations
import asyncio
import unittest
from types import SimpleNamespace
from unittest.mock import AsyncMock, patch
@@ -8,6 +9,30 @@ from services.conversation_history import ConversationRecorder
class ConversationRecorderTest(unittest.IsolatedAsyncioTestCase):
async def test_finish_waits_for_database_cleanup_when_cancelled(self):
recorder = ConversationRecorder("conv_test")
started = asyncio.Event()
release = asyncio.Event()
completed = asyncio.Event()
async def finish_database_write(*, status: str):
self.assertEqual(status, "failed")
started.set()
await release.wait()
completed.set()
recorder._finish = finish_database_write
task = asyncio.create_task(recorder.finish(status="failed"))
await started.wait()
task.cancel()
await asyncio.sleep(0)
self.assertFalse(task.done())
release.set()
with self.assertRaises(asyncio.CancelledError):
await task
self.assertTrue(completed.is_set())
async def test_fixed_reply_transcript_keeps_workflow_metadata(self):
recorder = ConversationRecorder("conv_test")
recorder._append = AsyncMock()