[CI][BugFix] Isolate controller mock to instance level#8092
Conversation
|
/skip-ci ci_iluvatar |
PaddlePaddle-bot
left a comment
There was a problem hiding this comment.
🤖 Paddle-CI-Agent | pr_review |
2026-07-02 13:28:46
📋 Review 摘要
PR 概述:将 CacheController 析构器单测中的 _free_host_cache mock 从类级 patch 改为当前 controller 实例属性,降低跨测试析构调用对 mock 计数的干扰。
变更范围:tests/cache_manager/v1/test_cache_controller.py
影响面 Tag:[KVCache]
问题
未发现阻塞性问题。PR 规范问题在下面章节报,不在这里重复。
📝 PR 规范检查
标题包含 [CI] 和 [BugFix] 两个官方 Tag;FastDeploy 普通 PR 标题规则要求仅保留一个官方 Tag。建议使用更贴合本次测试稳定性变更的标题:
标题建议(可直接复制):
[CI] Isolate controller mock to instance level
PR 描述已包含 ## Motivation、## Modifications、## Usage or Command、## Accuracy Tests、## Checklist,结构符合模板。
总体评价
代码改动与 PR 描述一致:实例级 MagicMock 只影响当前 controller,对 __del__ 的调用与异常吞掉路径仍有断言覆盖。未发现需要阻塞合入的代码问题;本地尝试执行 TestDestructor 失败,原因是当前环境缺少 paddle 依赖,未能完成运行时验证。
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #8092 +/- ##
==========================================
Coverage ? 77.53%
==========================================
Files ? 409
Lines ? 58174
Branches ? 9157
==========================================
Hits ? 45106
Misses ? 10199
Partials ? 2869
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Motivation
The cache controller unit test was affected by cross-test interference caused by mocking
_free_host_cacheat the class level or in a shared scope.When
MagicMockis applied globally, previously createdcontrollerinstances (from earlier tests or garbage collection remnants) may still reference the original method or a shared mock state. This leads to non-deterministic behavior in__del__()execution paths and inconsistent call tracking.Modifications
MagicMockassignment from global/class scope to instance scope:controller._free_host_cache = MagicMock()__dict__, so only the current test instance is affected._free_host_cache, allowing them to execute the real class method.__del__) to avoid interference from stale or previously collected objects.Usage or Command
N/A
Accuracy Tests
N/A
Checklist
[FDConfig],[APIServer],[Engine],[Scheduler],[PD Disaggregation],[Executor],[Graph Optimization],[Speculative Decoding],[RL],[Models],[Quantization],[Loader],[OP],[KVCache],[DataProcessor],[BugFix],[Docs],[CI],[Optimization],[Feature],[Benchmark],[Others],[XPU],[HPU],[GCU],[DCU],[Iluvatar],[Metax]]pre-commitbefore commit.releasebranch, make sure the PR has been submitted to thedevelopbranch, then cherry-pick it to thereleasebranch with the[Cherry-Pick]PR tag.