Skip to content

fix: restore dcgm_fakers after lifespan tests#999

Merged
debermudez merged 1 commit into
mainfrom
dbermudez/fix-dcgm-fakers
May 27, 2026
Merged

fix: restore dcgm_fakers after lifespan tests#999
debermudez merged 1 commit into
mainfrom
dbermudez/fix-dcgm-fakers

Conversation

@debermudez

@debermudez debermudez commented May 26, 2026

Copy link
Copy Markdown
Contributor

The lifespan tests drive async with lifespan(fastapi_app) directly, which unconditionally appends two DCGMFaker entries to the module-level aiperf_mock_server.app.dcgm_fakers list. Those appends leak across files: tests/unit/server/test_app.py::test_dcgm_metrics_invalid_instance asks for /dcgm3/metrics expecting 404, but with 4 fakers in the list it gets 200.

Add an autouse fixture that snapshots dcgm_fakers on entry and restores it in finally, isolating the leak regardless of whether the lifespan body errors out before yield.

Summary by CodeRabbit

  • Tests
    • Improved test reliability by fixing test isolation issues to prevent interference between mock server tests.

Review Change Stack

The lifespan tests drive `async with lifespan(fastapi_app)` directly,
which unconditionally appends two `DCGMFaker` entries to the
module-level `aiperf_mock_server.app.dcgm_fakers` list. Those appends
leak across files: `tests/unit/server/test_app.py::test_dcgm_metrics_invalid_instance`
asks for `/dcgm3/metrics` expecting 404, but with 4 fakers in the list
it gets 200.

Add an autouse fixture that snapshots `dcgm_fakers` on entry and
restores it in `finally`, isolating the leak regardless of whether the
lifespan body errors out before yield.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Signed-off-by: Elias Bermudez <dbermudez@nvidia.com>
@copy-pr-bot

copy-pr-bot Bot commented May 26, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@github-actions

Copy link
Copy Markdown

Try out this PR

Quick install:

pip install --upgrade --force-reinstall git+https://github.com/ai-dynamo/aiperf.git@191aef99ba5531ae38d92df6a42a3ebf6e89dead

Recommended with virtual environment (using uv):

uv venv --python 3.12 && source .venv/bin/activate
uv pip install --upgrade --force-reinstall git+https://github.com/ai-dynamo/aiperf.git@191aef99ba5531ae38d92df6a42a3ebf6e89dead

Last updated for commit: 191aef9Browse code

@github-actions github-actions Bot added the fix label May 26, 2026
@coderabbitai

coderabbitai Bot commented May 26, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

The PR adds a pytest fixture that manages test isolation for lifespan tests by capturing the module-level dcgm_fakers list state before each test and restoring it afterward, preventing cross-test state leakage from lifespan's unconditional list appends.

Changes

Lifespan test state isolation

Layer / File(s) Summary
State isolation fixture for lifespan tests
tests/unit/aiperf_mock_server/test_app_lifespan.py
An autouse fixture snapshots aiperf_mock_server.app.dcgm_fakers before each test and restores the original list in a finally block to isolate tests from lifespan's unconditional appends.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A fixture most fine, with snapshot care,
Restores the list to pristine air,
No leaks betwixt tests shall remain,
State isolation breaks the chain! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'fix: restore dcgm_fakers after lifespan tests' is clear, concise, and directly describes the main change—fixing test isolation by restoring module state after lifespan tests.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/unit/aiperf_mock_server/test_app_lifespan.py`:
- Around line 15-16: The fixture function _restore_dcgm_fakers is missing a
return type annotation; update its signature to annotate the return type as
Generator[None, None, None] (and add "from typing import Generator" if not
already imported) since this pytest fixture yields control, ensuring all
function return types follow the project's type-hinting guideline.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e37e9142-ed8e-4189-ba40-3a1293fb55ba

📥 Commits

Reviewing files that changed from the base of the PR and between 03167d0 and 191aef9.

📒 Files selected for processing (1)
  • tests/unit/aiperf_mock_server/test_app_lifespan.py
Comment thread tests/unit/aiperf_mock_server/test_app_lifespan.py
@codecov

codecov Bot commented May 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@debermudez debermudez merged commit 711a389 into main May 27, 2026
20 checks passed
@debermudez debermudez deleted the dbermudez/fix-dcgm-fakers branch May 27, 2026 00:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3 participants