fix: manage WebRTC pipeline shutdown
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user