Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions tests/unit/test_core_lifecycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,12 @@ async def test_restart_terminates_managers_and_starts_thread(

lifecycle.astrbot_updater = MagicMock()

with patch("astrbot.core.core_lifecycle.threading.Thread") as mock_thread:
# Patch the module reference used by the lifecycle code instead of the
# global ``threading.Thread``. ``restart()`` awaits
# ``asyncio.to_thread(...)``, whose ThreadPoolExecutor spawns its worker
# with ``threading.Thread``; a process-wide mock would make that worker
# a no-op MagicMock and hang the awaiting future forever.
with patch("astrbot.core.core_lifecycle.threading") as mock_threading:
await lifecycle.restart()

# Verify managers were terminated
Expand All @@ -904,8 +909,8 @@ async def test_restart_terminates_managers_and_starts_thread(
lifecycle.kb_manager.terminate.assert_awaited_once()

# Verify thread was started
mock_thread.assert_called_once()
mock_thread.return_value.start.assert_called_once()
mock_threading.Thread.assert_called_once()
mock_threading.Thread.return_value.start.assert_called_once()


class TestAstrBotCoreLifecycleLoadPipelineScheduler:
Expand Down