mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-05 23:47:41 +08:00
fix(imdb): register async cache cleanup
This commit is contained in:
+3
-2
@@ -13,8 +13,8 @@
|
||||
"runtime_to_db": [],
|
||||
"workflow_to_db": []
|
||||
},
|
||||
"edge_count": 6477,
|
||||
"edge_sha256": "41e51256026afbd3abc9684dd1beb653026be927cab14384df6ff6d248806972",
|
||||
"edge_count": 6478,
|
||||
"edge_sha256": "d1c26c72787d07b411f6e047863bfb135005be8d3cf2212f2f03e0d8e0326283",
|
||||
"edges": [
|
||||
"app -> app.runtime",
|
||||
"app -> app.runtime.compat",
|
||||
@@ -4322,6 +4322,7 @@
|
||||
"app.modules.imdb.api -> app.runtime.cache",
|
||||
"app.modules.imdb.api -> app.runtime.log",
|
||||
"app.modules.imdb.api -> app.runtime.settings",
|
||||
"app.modules.imdb.api -> app.runtime.tasks",
|
||||
"app.modules.indexer -> app.application",
|
||||
"app.modules.indexer -> app.application.site",
|
||||
"app.modules.indexer -> app.application.site.health",
|
||||
|
||||
@@ -20,6 +20,7 @@ from app.modules.imdb.api import (
|
||||
ImdbTitle,
|
||||
)
|
||||
from app.runtime.config import settings
|
||||
from app.runtime.tasks import TaskRegistry
|
||||
from app.schemas.types import MediaRecognizeType, MediaSource, MediaType
|
||||
|
||||
|
||||
@@ -168,6 +169,38 @@ def test_imdb_graphql_error_is_not_cached() -> None:
|
||||
assert api._request.post_json.call_count == 2
|
||||
|
||||
|
||||
def test_imdb_clear_cache_registers_async_cleanup_in_running_loop() -> None:
|
||||
"""同步清缓存入口在异步宿主中应登记任务,并保留原同步调用约定。"""
|
||||
|
||||
async def scenario() -> None:
|
||||
"""验证异步缓存清理直到完成前都由宿主登记器持有。"""
|
||||
api = ImdbApi()
|
||||
registry = TaskRegistry()
|
||||
release = asyncio.Event()
|
||||
|
||||
async def clear_async_cache() -> None:
|
||||
"""等待测试释放,确保可以观察登记中的任务。"""
|
||||
await release.wait()
|
||||
|
||||
with (
|
||||
patch("app.modules.imdb.api.get_task_registry", return_value=registry),
|
||||
patch.object(api, "async_clear_cache", side_effect=clear_async_cache),
|
||||
):
|
||||
assert api.clear_cache() is None
|
||||
assert [record.owner for record in registry.records] == [
|
||||
"module.imdb.cache_clear"
|
||||
]
|
||||
|
||||
release.set()
|
||||
await registry.records[0].task
|
||||
await asyncio.sleep(0)
|
||||
|
||||
assert registry.records == ()
|
||||
api.close()
|
||||
|
||||
asyncio.run(scenario())
|
||||
|
||||
|
||||
def test_async_imdb_api_merges_paginated_episodes() -> None:
|
||||
"""IMDb 异步剧集查询应使用 GraphQL 游标合并并缓存所有分页。"""
|
||||
api = ImdbApi()
|
||||
|
||||
Reference in New Issue
Block a user