[CI]【Hackathon 10th Spring No.36】worker_process unit test#7493
Open
bobby-cloudforge wants to merge 1 commit intoPaddlePaddle:developfrom
Open
[CI]【Hackathon 10th Spring No.36】worker_process unit test#7493bobby-cloudforge wants to merge 1 commit intoPaddlePaddle:developfrom
bobby-cloudforge wants to merge 1 commit intoPaddlePaddle:developfrom
Conversation
|
Thanks for your contribution! |
PaddlePaddle-bot
left a comment
There was a problem hiding this comment.
🤖 AI Code Review |
2026-04-20 04:04 CST
📋 Review 摘要
PR 概述:为 fastdeploy/worker/worker_process.py 补充单元测试,覆盖率从 64% 提升至 80%
变更范围:tests/worker/test_worker_process.py(纯新增测试)
影响面 Tag:CI
问题
| 级别 | 文件 | 概述 |
|---|---|---|
| 🟡 建议 | tests/worker/test_worker_process.py:230 |
lambda *a, **kw: sentinel 不验证 Worker 构造参数 |
总体评价
测试整体质量较高,覆盖了 get_worker 平台分发、init_distributed_environment、initialize_fd_config、PaddleDisWorkerProc 构造/KV Cache/EPLB/Barrier 等核心路径,mock 设计合理。_make_config 辅助函数通过 dotted-path override 模式简洁灵活。仅有一处小建议可改进测试的健壮性。
| getattr(plat, a).return_value = a == plat_name | ||
| sentinel = object() | ||
| with patch.dict( | ||
| "sys.modules", {mod_path: types.SimpleNamespace(**{cls_name: lambda *a, **kw: sentinel})} |
There was a problem hiding this comment.
🟡 建议 lambda *a, **kw: sentinel 不验证传入参数
此处 lambda 会忽略所有传入的参数(fd_config、local_rank、rank),如果 get_worker 源码传参方式发生变更(如新增必需参数),测试也不会失败。
建议改用 Mock(return_value=sentinel) 并在断言后验证调用参数:
worker_cls = Mock(return_value=sentinel)
with patch.dict("sys.modules", {mod_path: types.SimpleNamespace(**{cls_name: worker_cls})}):
result = get_worker(_make_config(), local_rank=0, rank=1)
self.assertIs(result, sentinel)
worker_cls.assert_called_once()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
No.36 功能模块 fastdeploy/worker/worker_process.py 补充单元测试
Modifications
新增单元测试 tests/worker/test_worker_process.py
develop 分支:覆盖率64%,Miss行数160(86-88, 93-112, 135, 195-211, 315-329, 332-335, 347-400, 414-451, 467-468, 479-480, 498-500, 508->517, 512, 520-570, 580, 587, 598->617, 601, 608-615, 617->639, 640-643, 650-653, 661-662, 674, 717, 740, 750-756, 770, 1191-1192, 1197-1208, 1235, 1270-1271, 1300, 1326-1328, 1340-1344)
当前PR:覆盖率80%,Miss行数106
新增覆盖行数 160-106 = 54 → 四舍五入 100 → 预计贡献 0.1⭐
Usage or Command
Accuracy Tests
not required
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.