Skip to content

[CI]【Hackathon 9th Sprint No.40】功能模块 fastdeploy/entrypoints/openai/api_server.py 单测补充#5567

Merged
CSWYF3634076 merged 26 commits intoPaddlePaddle:developfrom
kesmeey:40
Dec 23, 2025
Merged

[CI]【Hackathon 9th Sprint No.40】功能模块 fastdeploy/entrypoints/openai/api_server.py 单测补充#5567
CSWYF3634076 merged 26 commits intoPaddlePaddle:developfrom
kesmeey:40

Conversation

@kesmeey
Copy link
Collaborator

@kesmeey kesmeey commented Dec 15, 2025

Motivation

功能模块 fastdeploy/entrypoints/openai/api_server.py 单测补充

image develop分支 ,覆盖率42%,Miss行数215(85, 104, 113, 119-120, 131-142, 150-243, 263-268, 278-284, 309-317, 323, 345-351, 354->356, 374-398, 406-425, 433-442, 450-456, 464-470, 478-484, 492-498, 506-508, 516-518, 526-528, 536, 554, 604, 610, 627-632, 641-666, 673, 687-692, 702-709, 720-723, 729) 7705cbe00f2e410a64b05045f2415aca 当前pr,覆盖率86%,miss行数 59

完成单测覆盖行数215-59=156

Modifications

add unittest tests/entrypoints/openai/test_api_server.py

Usage or Command

No need

Accuracy Tests

No need

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.

Copilot AI review requested due to automatic review settings December 15, 2025 11:30
@paddle-bot
Copy link

paddle-bot bot commented Dec 15, 2025

Thanks for your contribution!

@paddle-bot paddle-bot bot added the contributor External developers label Dec 15, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds comprehensive unit test coverage for the fastdeploy/entrypoints/openai/api_server.py module as part of Hackathon 9th Sprint No.40. The tests focus on previously uncovered code branches using mocks to isolate the API server logic from heavy dependencies.

Key changes:

  • Adds 546 lines of test coverage for api_server.py
  • Tests include lifecycle management, connection handling, route handlers, and server launchers
  • Uses extensive mocking to test various error paths and edge cases

@@ -0,0 +1,546 @@
"""
Copy link

Copilot AI Dec 15, 2025

Choose a reason for hiding this comment

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

PR标题中存在文字重复问题:"功能模块 f功能模块"。建议修改为:"[CI]【Hackathon 9th Sprint No.40】fastdeploy/entrypoints/openai/api_server.py 单测补充" 或 "[CI]【Hackathon 9th Sprint No.40】功能模块 fastdeploy/entrypoints/openai/api_server.py 单测补充"。

For external contributors: The PR title contains a duplication issue in "功能模块 f功能模块". Please revise to either "[CI]【Hackathon 9th Sprint No.40】fastdeploy/entrypoints/openai/api_server.py unit test coverage" or remove the duplicated text.

Copilot generated this review using guidance from repository custom instructions.
api_server = _reload_api_server(args)

class SlowSemaphore:
async def acquire(self):
Copy link

Copilot AI Dec 15, 2025

Choose a reason for hiding this comment

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

The sleep time of 0.01 seconds is intentionally longer than the connection_manager timeout of 0.001 seconds to trigger the timeout exception. Consider adding a brief comment explaining this relationship for better test maintainability.

Suggested change
async def acquire(self):
async def acquire(self):
# The sleep time of 0.01 seconds is intentionally longer than the
# connection_manager timeout of 0.001 seconds to trigger the timeout exception.

Copilot uses AI. Check for mistakes.
assert ping_resp.status_code == 304 # line 323

routes = api_server.list_all_routes()
assert isinstance(routes, dict) and routes["routes"] # lines 309-317
Copy link

Copilot AI Dec 15, 2025

Choose a reason for hiding this comment

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

The assertion on line 267 could be more explicit. Consider splitting it into two separate assertions for better test failure diagnostics: assert isinstance(routes, dict) followed by assert "routes" in routes and routes["routes"]. This makes it clearer which specific condition failed if the test breaks.

Suggested change
assert isinstance(routes, dict) and routes["routes"] # lines 309-317
assert isinstance(routes, dict)
assert "routes" in routes and routes["routes"] # lines 309-317

Copilot uses AI. Check for mistakes.
Comment on lines +1 to +5
"""
Extra coverage for `fastdeploy.entrypoints.openai.api_server`.
Tests are lightweight and mock heavy dependencies to exercise branches
that were previously uncovered.
"""
Copy link

Copilot AI Dec 15, 2025

Choose a reason for hiding this comment

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

The file is missing the standard Apache 2.0 copyright header that is present in all other test files in this directory. Please add the copyright header at the beginning of the file, following the same format as other test files like test_api_authentication.py.

Copilot uses AI. Check for mistakes.
Copy link
Collaborator

Choose a reason for hiding this comment

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

这个需要关注一下

Comment on lines +507 to +516
models_resp_fail = asyncio.run(api_server.list_models())
assert models_resp_fail.status_code == 304 # lines 433-437

# list_models success ModelList branch
api_server.app.state.dynamic_load_weight = False
api_server.app.state.model_handler = MagicMock(
list_models=AsyncMock(return_value=SimpleNamespace(model_dump=lambda: {"models": [1]}))
)
models_resp = asyncio.run(api_server.list_models())
assert models_resp.status_code == 200 # lines 433-442
Copy link

Copilot AI Dec 15, 2025

Choose a reason for hiding this comment

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

The function test_controller_routes_and_models_listing uses asyncio.run to call async functions (list_models), but this is inconsistent with the test pattern used elsewhere in this file where async functions are tested with @pytest.mark.asyncio. Consider marking this test as async and using await instead of asyncio.run for consistency and to avoid potential issues with nested event loops.

Copilot uses AI. Check for mistakes.
@kesmeey kesmeey changed the title [CI]【Hackathon 9th Sprint No.40】功能模块 f功能模块 fastdeploy/entrypoints/openai/api_server.py 单测补充 [CI]【Hackathon 9th Sprint No.40】功能模块 fastdeploy/entrypoints/openai/api_server.py 单测补充 Dec 15, 2025
@codecov-commenter
Copy link

codecov-commenter commented Dec 15, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (develop@c1aa66d). Learn more about missing BASE report.

Additional details and impacted files
@@            Coverage Diff             @@
##             develop    #5567   +/-   ##
==========================================
  Coverage           ?   65.50%           
==========================================
  Files              ?      329           
  Lines              ?    41783           
  Branches           ?     6396           
==========================================
  Hits               ?    27368           
  Misses             ?    12383           
  Partials           ?     2032           
Flag Coverage Δ
GPU 65.50% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@EmmonsCurse
Copy link
Collaborator

@kesmeey 辛苦按照 Codestyle-Check / Pre Commit (pull_request) 的报错信息做下修改,然后因为有其他已知问题,后续更新 PR 时候,请 rebase 一下最新代码后重新提交~

@kesmeey kesmeey force-pushed the 40 branch 2 times, most recently from f49e576 to 16a194d Compare December 18, 2025 01:33
@CSWYF3634076
Copy link
Collaborator

@EmmonsCurse 可以review下_base_test.yml部分

EmmonsCurse
EmmonsCurse previously approved these changes Dec 23, 2025
Copy link
Collaborator

@EmmonsCurse EmmonsCurse left a comment

Choose a reason for hiding this comment

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

LGTM for download run_try~

sunlei1024
sunlei1024 previously approved these changes Dec 23, 2025
Removed unnecessary docstring from test_api_server.py
@CSWYF3634076 CSWYF3634076 merged commit f15edbb into PaddlePaddle:develop Dec 23, 2025
15 of 18 checks passed
@CSWYF3634076
Copy link
Collaborator

0.2⭐️
@luotao1

ckl117 pushed a commit to fxyfxy777/FastDeploy that referenced this pull request Dec 29, 2025
…i_server.py 单测补充 (PaddlePaddle#5567)

* Add tests for openai api_server coverage

* update

* Update tests for openai api_server

* fix bugs

* test: disable some api_server lifespan/controller tests for local env

* Format test_api_server with black

* update

* update

* test: narrow envs patch in api_server tests to avoid side effects

* fix: separate MagicMock creation to avoid missing req argument

* fix: patch TRACES_ENABLE env var in api_server tests

* fix: use os.environ patch for TRACES_ENABLE

* test: use fake fastdeploy.envs in api_server tests

* test: pass fake Request into chat/completion routes

* test: increase coverage for tracing and scheduler control

* fix: set dynamic_load_weight in tracing headers test

* ci: add retry and validation for FastDeploy.tar.gz download

* ci: fix indentation in _base_test.yml

* refactor: simplify test_api_server.py (807->480 lines, ~40% reduction)

* fix: restore missing args attributes (revision, etc.) in _build_args

* fix: patch sys.argv to prevent SystemExit: 2 in api_server tests

* improve coverage

* Remove docstring from test_api_server.py

Removed unnecessary docstring from test_api_server.py

---------

Co-authored-by: CSWYF3634076 <wangyafeng@baidu.com>
chang-wenbin pushed a commit to chang-wenbin/FastDeploy that referenced this pull request Mar 2, 2026
…i_server.py 单测补充 (PaddlePaddle#5567)

* Add tests for openai api_server coverage

* update

* Update tests for openai api_server

* fix bugs

* test: disable some api_server lifespan/controller tests for local env

* Format test_api_server with black

* update

* update

* test: narrow envs patch in api_server tests to avoid side effects

* fix: separate MagicMock creation to avoid missing req argument

* fix: patch TRACES_ENABLE env var in api_server tests

* fix: use os.environ patch for TRACES_ENABLE

* test: use fake fastdeploy.envs in api_server tests

* test: pass fake Request into chat/completion routes

* test: increase coverage for tracing and scheduler control

* fix: set dynamic_load_weight in tracing headers test

* ci: add retry and validation for FastDeploy.tar.gz download

* ci: fix indentation in _base_test.yml

* refactor: simplify test_api_server.py (807->480 lines, ~40% reduction)

* fix: restore missing args attributes (revision, etc.) in _build_args

* fix: patch sys.argv to prevent SystemExit: 2 in api_server tests

* improve coverage

* Remove docstring from test_api_server.py

Removed unnecessary docstring from test_api_server.py

---------

Co-authored-by: CSWYF3634076 <wangyafeng@baidu.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants