mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-05 23:47:41 +08:00
fix(database): harden worker shutdown and overload propagation
This commit is contained in:
@@ -2,6 +2,7 @@ from unittest.mock import AsyncMock, Mock
|
||||
|
||||
import pytest
|
||||
|
||||
from app.application.database import DatabaseWorkerOverloadedError
|
||||
from app.application.plugin.install import PluginInstallCommand
|
||||
|
||||
|
||||
@@ -181,6 +182,26 @@ async def test_persistence_failure_restores_package_without_touching_runtime():
|
||||
reloader.assert_not_awaited()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_database_worker_overload_rolls_back_and_reaches_api_boundary():
|
||||
"""配置 worker 背压完成补偿后继续抛出,交由 API 映射为 503。"""
|
||||
checkpoint = object()
|
||||
rollback = AsyncMock()
|
||||
command = _command(
|
||||
checkpointer=AsyncMock(return_value=checkpoint),
|
||||
writer=AsyncMock(side_effect=DatabaseWorkerOverloadedError("worker full")),
|
||||
rollback=rollback,
|
||||
)
|
||||
|
||||
with pytest.raises(DatabaseWorkerOverloadedError):
|
||||
await command.execute(
|
||||
plugin_id="DemoPlugin",
|
||||
repo_url="https://github.com/demo/plugins",
|
||||
)
|
||||
|
||||
rollback.assert_awaited_once_with(checkpoint)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_reload_failure_restores_list_files_and_previous_runtime():
|
||||
"""重载失败时依次恢复已安装列表、包文件和旧运行态。"""
|
||||
|
||||
Reference in New Issue
Block a user