mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-05 15:38:19 +08:00
refactor: own legacy subscription report tasks
This commit is contained in:
+4
-2
@@ -13,8 +13,8 @@
|
||||
"runtime_to_db": [],
|
||||
"workflow_to_db": []
|
||||
},
|
||||
"edge_count": 6541,
|
||||
"edge_sha256": "c7e2a8537efa709d30c82930fa4ee21d91fe8f24578a44b4357563fa7bfc1a0c",
|
||||
"edge_count": 6543,
|
||||
"edge_sha256": "b9b6ba268382e7027f5557643defb09848c054cb68079345f2394d9b7faeb42c",
|
||||
"edges": [
|
||||
"app -> app.runtime",
|
||||
"app -> app.runtime.compat",
|
||||
@@ -89,9 +89,11 @@
|
||||
"app.adapters.external.server -> app.domain.meta.metabase",
|
||||
"app.adapters.external.server -> app.runtime",
|
||||
"app.adapters.external.server -> app.runtime.cache",
|
||||
"app.adapters.external.server -> app.runtime.config",
|
||||
"app.adapters.external.server -> app.runtime.log",
|
||||
"app.adapters.external.server -> app.runtime.observability",
|
||||
"app.adapters.external.server -> app.runtime.settings",
|
||||
"app.adapters.external.server -> app.runtime.tasks",
|
||||
"app.adapters.external.server -> app.schemas",
|
||||
"app.adapters.external.server -> app.schemas.media",
|
||||
"app.adapters.external.server -> app.schemas.types",
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
"""服务端统计兼容入口的后台任务生命周期回归。"""
|
||||
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
from app.adapters.external.server import MoviePilotServerHelper
|
||||
from app.runtime.config import global_vars
|
||||
|
||||
|
||||
def test_legacy_subscription_reports_use_owned_threadsafe_tasks() -> None:
|
||||
"""旧同步统计入口应保留 ABI,并让宿主等待已开始的线程工作。"""
|
||||
loop = Mock(**{"is_running.return_value": True, "is_closed.return_value": False})
|
||||
registry = Mock()
|
||||
|
||||
def submit(coroutine, **_kwargs):
|
||||
"""关闭测试协程,避免替身提交留下未等待警告。"""
|
||||
coroutine.close()
|
||||
return Mock()
|
||||
|
||||
registry.submit_threadsafe.side_effect = submit
|
||||
with patch.object(global_vars, "CURRENT_EVENT_LOOP", loop), patch(
|
||||
"app.adapters.external.server.get_task_registry", return_value=registry
|
||||
):
|
||||
assert MoviePilotServerHelper.sub_reg_async({"media_id": "1"}) is True
|
||||
assert MoviePilotServerHelper.sub_done_async({"media_id": "1"}) is True
|
||||
|
||||
assert registry.submit_threadsafe.call_count == 2
|
||||
assert registry.submit_threadsafe.call_args_list[0].kwargs == {
|
||||
"loop": loop,
|
||||
"owner": "compat.server.subscribe_added_report",
|
||||
"cancel_on_shutdown": False,
|
||||
}
|
||||
assert registry.submit_threadsafe.call_args_list[1].kwargs == {
|
||||
"loop": loop,
|
||||
"owner": "compat.server.subscribe_done_report",
|
||||
"cancel_on_shutdown": False,
|
||||
}
|
||||
|
||||
|
||||
def test_legacy_subscription_report_rejects_without_runtime_loop() -> None:
|
||||
"""宿主生命周期不可用时应拒绝提交,并保持布尔返回合同。"""
|
||||
with patch.object(global_vars, "CURRENT_EVENT_LOOP", None):
|
||||
assert MoviePilotServerHelper.sub_done_async({"media_id": "1"}) is False
|
||||
Reference in New Issue
Block a user