mirror of
https://github.com/basicmachines-co/basic-memory
synced 2026-06-21 13:47:35 +00:00
c755127317
Signed-off-by: rudi193-cmd <rudi193@gmail.com> Co-authored-by: Cursor <cursoragent@cursor.com>
39 lines
1.0 KiB
Python
39 lines
1.0 KiB
Python
"""Tests for background task done-callback error handling."""
|
|
|
|
import asyncio
|
|
from unittest.mock import patch
|
|
|
|
import pytest
|
|
|
|
from basic_memory.deps.services import _log_task_failure
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_log_task_failure_ignores_cancelled_task():
|
|
async def slow():
|
|
await asyncio.sleep(10)
|
|
|
|
task = asyncio.create_task(slow())
|
|
task.cancel()
|
|
with pytest.raises(asyncio.CancelledError):
|
|
await task
|
|
|
|
with patch("basic_memory.deps.services.logger.exception") as mock_exc:
|
|
_log_task_failure(task)
|
|
mock_exc.assert_not_called()
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_log_task_failure_logs_real_exception():
|
|
async def boom():
|
|
raise ValueError("sync failed")
|
|
|
|
task = asyncio.create_task(boom())
|
|
with pytest.raises(ValueError):
|
|
await task
|
|
|
|
with patch("basic_memory.deps.services.logger.exception") as mock_exc:
|
|
_log_task_failure(task)
|
|
mock_exc.assert_called_once()
|
|
assert "sync failed" in str(mock_exc.call_args)
|