Skip to content

[CI]【Hackathon 10th Spring No.36】worker_process unit test#7493

Open
bobby-cloudforge wants to merge 1 commit intoPaddlePaddle:developfrom
CloudForge-Solutions:task/h10-36-worker-process-unittest1
Open

[CI]【Hackathon 10th Spring No.36】worker_process unit test#7493
bobby-cloudforge wants to merge 1 commit intoPaddlePaddle:developfrom
CloudForge-Solutions:task/h10-36-worker-process-unittest1

Conversation

@bobby-cloudforge
Copy link
Copy Markdown

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

注:截图来自本测试文件独立运行 pytest --cov 的输出(含 branch coverage),上方文字为 develop 已有测试与本 PR 合并后的 statement 覆盖率预估,两者统计口径不同,以 CI 合并后实际结果为准。

新增覆盖行数 160-106 = 54 → 四舍五入 100 → 预计贡献 0.1⭐

Usage or Command

pytest tests/worker/test_worker_process.py

Accuracy Tests

not required

Checklist

  • Add at least a tag in the PR title.
    • Tag list: [[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]]
    • You can add new tags based on the PR content, but the semantics must be clear.
  • Format your code, run pre-commit before commit.
  • Add unit tests. Please write the reason in this PR if no unit tests.
  • Provide accuracy results.
  • If the current PR is submitting to the release branch, make sure the PR has been submitted to the develop branch, then cherry-pick it to the release branch with the [Cherry-Pick] PR tag.

@paddle-bot
Copy link
Copy Markdown

paddle-bot bot commented Apr 19, 2026

Thanks for your contribution!

@paddle-bot paddle-bot bot added the contributor External developers label Apr 19, 2026
Copy link
Copy Markdown

@PaddlePaddle-bot PaddlePaddle-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AI Code Review | 2026-04-20 04:04 CST

📋 Review 摘要

PR 概述:为 fastdeploy/worker/worker_process.py 补充单元测试,覆盖率从 64% 提升至 80%
变更范围tests/worker/test_worker_process.py(纯新增测试)
影响面 TagCI

问题

级别 文件 概述
🟡 建议 tests/worker/test_worker_process.py:230 lambda *a, **kw: sentinel 不验证 Worker 构造参数

总体评价

测试整体质量较高,覆盖了 get_worker 平台分发、init_distributed_environmentinitialize_fd_configPaddleDisWorkerProc 构造/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})}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 建议 lambda *a, **kw: sentinel 不验证传入参数

此处 lambda 会忽略所有传入的参数(fd_configlocal_rankrank),如果 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()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor External developers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants