Skip to content

test(kunlun): raise vdevice.go coverage up to 95% - #2176

Merged
hami-robot[bot] merged 2 commits into
Project-HAMi:masterfrom
adity1raut:test/kunlun-vdevice-coverage
Jul 31, 2026
Merged

test(kunlun): raise vdevice.go coverage up to 95%#2176
hami-robot[bot] merged 2 commits into
Project-HAMi:masterfrom
adity1raut:test/kunlun-vdevice-coverage

Conversation

@adity1raut

@adity1raut adity1raut commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this?

/kind feature

What this PR does / why we need it:

  • Add unit tests for the KunlunVDevices methods that previously had no direct coverage: InitKunlunVDevice, trimMemory, MutateAdmission, CheckHealth, NodeCleanUp, GetNodeDevices, PatchAnnotations, LockNode, ReleaseNodeLock, CheckType, GenerateResourceRequests, ScoreNode, AddResourceUsage, GetResourceNames, and FitVXPU.
image

Which issue(s) this PR fixes:
Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

Summary by CodeRabbit

  • Tests
    • Added comprehensive automated coverage for Kunlun virtual device initialization, memory handling, admission behavior, and admission-related resource request initialization.
    • Added validation for device discovery, node health classification, cleanup behavior, node locking, annotation updates, and device matching.
    • Added tests for scoring, resource usage tracking, resource naming, and virtual-device placement feasibility.

Add unit tests for the KunlunVDevices methods that previously had no
direct coverage: InitKunlunVDevice, trimMemory, MutateAdmission,
CheckHealth, NodeCleanUp, GetNodeDevices, PatchAnnotations, LockNode,
ReleaseNodeLock, CheckType, GenerateResourceRequests, ScoreNode,
AddResourceUsage, GetResourceNames, and FitVXPU.

LockNode/ReleaseNodeLock/CheckHealth/NodeCleanUp tests use a fake
Kubernetes clientset (client.KubeClient = fake.NewClientset()),
following the same pattern already used in the hygon and biren device
test suites.

Signed-off-by: Aditya Raut <araut7798@gmail.com>
@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 45132c50-440e-40f7-8adc-d635b1532afa

📥 Commits

Reviewing files that changed from the base of the PR and between c4a3511 and f390af3.

📒 Files selected for processing (2)
  • pkg/device/kunlun/vdevice.go
  • pkg/device/kunlun/vdevice_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/device/kunlun/vdevice_test.go

📝 Walkthrough

Walkthrough

Adds comprehensive unit tests for Kunlun virtual device initialization, admission mutation, node state handling, annotations, locking, resource accounting, scoring, and VXPU fitting. Admission mutation also initializes nil resource request maps before writing memory requests.

Changes

Kunlun virtual device tests

Layer / File(s) Summary
Configuration and admission behavior
pkg/device/kunlun/vdevice.go, pkg/device/kunlun/vdevice_test.go
Tests resource mappings, idempotent initialization, memory trimming, device identity, and admission mutation, including nil request handling.
Node health and device annotations
pkg/device/kunlun/vdevice_test.go
Covers handshake health states, cleanup, device-list parsing, and pod annotation patching.
Node locking and resource requests
pkg/device/kunlun/vdevice_test.go
Validates device matching, lock acquisition and release, and resource request generation.
Scoring, usage, and device fitting
pkg/device/kunlun/vdevice_test.go
Tests node scoring, usage aggregation, resource names, and direct VXPU fit decisions.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested reviewers: ouyangluwei163

Poem

I’m a rabbit with tests in a row,
Checking Kunlun’s resources flow.
Locks click, annotations shine,
Memory fits by measured line.
Hop through health, requests, and score—
Reliable paths from core to door!

🚥 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 title clearly matches the main change: adding Kunlun tests to raise vdevice coverage.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 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 `@pkg/device/kunlun/vdevice_test.go`:
- Around line 43-55: Strengthen Test_InitKunlunVDevice by reasserting after the
second InitKunlunVDevice call that device.InRequestDevices[XPUDevice],
device.SupportDevices[XPUDevice], and util.HandshakeAnnos[XPUDevice] still equal
their expected values. Keep the existing non-nil assertion and initial
registration checks unchanged.
- Around line 109-122: Guard Resources.Requests before writing the trimmed
KunlunResourceVMemory value in MutateAdmission. Initialize the request resource
list when it is nil, then perform the existing assignment; preserve current
behavior when Requests is already populated.
- Around line 288-328: Initialize Kunlun configuration before constructing
resource-name fixtures in both Test_KunlunVDevices_LockNode and
Test_KunlunVDevices_ReleaseNodeLock. In pkg/device/kunlun/vdevice_test.go lines
288-328 and 330-378, move InitKunlunVDevice(testVConfig()) to the start of each
test function before its tests literal, and remove the per-subtest
initialization from each t.Run closure.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 4f4c2c7a-b547-4aad-95e7-455ffdc1bae8

📥 Commits

Reviewing files that changed from the base of the PR and between 37730dd and c4a3511.

📒 Files selected for processing (1)
  • pkg/device/kunlun/vdevice_test.go

Comment thread pkg/device/kunlun/vdevice_test.go
Comment thread pkg/device/kunlun/vdevice_test.go
Comment thread pkg/device/kunlun/vdevice_test.go
@github-actions github-actions Bot removed the kind/feature new function label Jul 28, 2026
@archlitchi

Copy link
Copy Markdown
Member

could you resolve these comments?

@codecov

codecov Bot commented Jul 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Flag Coverage Δ
unittests 64.02% <100.00%> (+2.02%) ⬆️

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

Files with missing lines Coverage Δ
pkg/device/kunlun/vdevice.go 98.14% <100.00%> (+76.89%) ⬆️

... and 7 files with indirect coverage changes

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

@mesutoezdil mesutoezdil 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.

every other test passes on its own, these 2 dont?

$ go test ./pkg/device/kunlun/ -run '^Test_KunlunVDevices_LockNode$' -count=1
--- FAIL: Test_KunlunVDevices_LockNode/container_requesting_xpu_locks_node
    vdevice_test.go:325: assertion failed: false (ok bool) != true (test.hasLock bool)

also no ai disclosure in the description, see https://github.com/Project-HAMi/HAMi/blob/master/CONTRIBUTING.md#ai-assistance-notice

Comment thread pkg/device/kunlun/vdevice_test.go
Comment thread pkg/device/kunlun/vdevice_test.go
Signed-off-by: Aditya Raut <araut7798@gmail.com>

@archlitchi archlitchi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

/lgtm

@hami-robot

hami-robot Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: adity1raut, archlitchi

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants