test: cover scrapeDCGMPerCluster branches in pkg/api/gpuworker [quality] - #23745
Conversation
scrapeDCGMPerCluster had 0% coverage even under the aggregated pkg/api go-test
run because no existing test drove Worker.collectUtilization far enough to
invoke it with a non-empty reservation list AND the DCGM flag enabled.
Add three direct unit tests covering the observable behaviours the per-
reservation collector relies on:
1. DCGM disabled (default) returns nil so callers fall back to the legacy
zero-memory path.
2. DCGM enabled with no reservations returns a non-nil empty map.
3. DCGM enabled with reservations for unreachable clusters silently drops
them (no partial data, no panic). Duplicate cluster entries exercise the
unique-cluster set path.
Package coverage rises from 41.5% to 49.7% (function 0% -> 66.7%). No
production code changes.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: kubestellar-hive[bot] <223556219+Copilot@users.noreply.github.com>
✅ Deploy Preview for kubestellarconsole canceled.
|
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
👋 Hey @hivecommons-hive[bot] — thanks for opening this PR!
This is an automated message. |
There was a problem hiding this comment.
Verified this against the tree at head cade3c7f, not just the diff.
- The three tests match the actual control flow in
pkg/api/gpuworker/worker.go:222-268:!w.dcgmEnabled→nil(worker.go:226), enabled with no reservations → non-nil empty map (worker.go:239make(...)returned as-is), andGetRestConfigfailure →continue, dropping the cluster silently (worker.go:245-249). GetRestConfigfor an unknown context fails viaGetClient(pkg/k8s/client_clients.go:85-90), so the "unreachable clusters" test is deterministic — I ran it from inside a pod where in-cluster config is detected, andc1/c2still correctly fail as unknown contexts. Passes in the worst-case environment.- Re-ran
go test -coverprofile ./pkg/api/gpuworker/:scrapeDCGMPerCluster66.7%, package total 49.7% — the PR body's numbers are exact. - Test-only change; no production code touched; construction pattern (
k8s.NewMultiClusterClient("")+t.Setenv) matches the existing tests at worker_test.go:376-417.
Looks correct to me. No findings.
— hive: agent=reviewer backend=copilot model=claude-fable-5 copilot=1.0.88
|
Thank you for your contribution! Your PR has been merged. Check out what's new:
Stay connected: Slack #kubestellar-dev | Multi-Cluster Survey |
|
Post-merge build verification passed ✅ Both Go and frontend builds compiled successfully against merge commit |
✅ Post-Merge Verification: passedCommit: |
Test Improvement
Worker.scrapeDCGMPerClusterinpkg/api/gpuworker/worker.gohad 0% coverage, even under the aggregatedpkg/apigo-test run (go tool cover -funcon the CI-style profile), because no existing test droveWorker.collectUtilizationfar enough to invoke it with a non-empty reservation list AND the DCGM flag enabled.This PR adds three direct unit tests covering the observable behaviours the per-reservation collector depends on:
nil— callers fall back to the legacy zero-memory path.Coverage impact
Standalone
go test ./pkg/api/gpuworker/:scrapeDCGMPerClusterThe new tests are pure unit tests — no k8s API server, no HTTP mock — and add ~30ms to the package suite.
No production code is modified.
Filed by quality agent (ACMM L4/L6 — full mode)
— hive: agent=quality backend=copilot model=claude-opus-4.7 copilot=1.0.88