test(scheduler): add unit tests for YuniKorn resource usage calculations #3231
All Vouch review confidence checks passed
Residual risk 0.31 = Change Risk (0.52) × (1 − Review Confidence (0.41)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 416 lines diff across 5 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.361
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #3231"
general
weight: 0.35
vjanelle
Purpose of this PR
internal/scheduler/yunikorn/resourceusagehad 16.5% statement coverage. OnlybyteStringAsBytes,bytesToMiandcpuRequesthad direct tests. The entire memory calculation chain — the part that decides what CPU and memory YuniKorn actually reserves for driver and executor pods — was exercised only indirectly, throughTestSchedulein the parent package.This adds direct table tests for that chain. Coverage goes from 16.5% to 97.8%. No production code is touched.
Part of #3202.
Proposed changes:
memory_test.goforisJavaApp,getMemoryOverheadFactor,memoryRequestBytes,executorPysparkMemoryBytes,sparkOffHeapMemoryBytes,driverMemoryRequestandexecutorMemoryRequest, including their error paths.resource_usage_test.goforDriverPodRequestsandExecutorPodRequests, covering defaults,coreRequestprecedence overcores, and error propagation.Change Category
<!-- Test-only change; none of the categories below apply. -->
Rationale
These functions encode Spark's memory-overhead semantics, which are easy to get wrong and currently unpinned by any test. The cases added lock down:
memoryOverheadandmemoryOverheadFactorover the type-derived defaults;spark.executor.pyspark.memory, matching Spark's documented behaviour;BasicDriverFeatureStep/BasicExecutorFeatureStep.Expected values were derived from the Spark semantics rather than from current output, so these are regression tests, not a snapshot of existing behaviour.
Checklist
Additional Notes
Local run:
The residual ~2% is the
strconv.ParseInterror branch inbyteStringAsBytes, which is unreachable because the preceding regex already guarantees the capture group is digits.@nabuskey @vjanelle @tariq-hasan One observation found while writing these, not addressed here:
sparkOffHeapMemoryBytescomparesspark.memory.offHeap.enabledagainst the exact string"false", so"False"or"FALSE"would be treated as enabled. Spark parses this case-insensitively. I deliberately did not add a test for it, since that would pin the current behaviour rather than flag it. Happy to open a separate issue if maintainers agree it's worth fixing.