You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@texera.apache.org by "PG1204 (via GitHub)" <gi...@apache.org> on 2026/07/15 01:10:54 UTC

[PR] test(frontend): add unit tests for computing-unit.util resource helpers [texera]

PG1204 opened a new pull request, #6435:
URL: https://github.com/apache/texera/pull/6435

   ### What changes were proposed in this PR?
   Adds unit test coverage for the pure resource-helper functions in [frontend/src/app/common/util/computing-unit.util.ts](vscode-webview://1epki5h79lmkghv36u4evg54fuvmk17ndjca203mcg7opnnd5sg9/frontend/src/app/common/util/computing-unit.util.ts), which previously had no direct test coverage. These functions parse Kubernetes resource strings, compute CPU/memory usage percentages, and derive UI status indicators.
   
   A new spec file, frontend/src/app/common/util/computing-unit.util.spec.ts, was created following the style of size-formatter.util.spec.ts (same directory). It adds 34 tests covering all 15 exported functions:
   
   parseResourceUnit / parseResourceNumber - unit extraction, decimals, and empty/NaN/invalid inputs
   cpuResourceConversion / memoryResourceConversion - precision scaling per target unit
   cpuPercentage / memoryPercentage - N/A and non-positive-limit guards, and the 100% clamp
   validateName - empty names, the 128-character boundary, and valid names
   getComputingUnitBadgeColor / getComputingUnitStatusTooltip - status mapping with fallback
   getComputingUnitCpuStatus / getComputingUnitMemoryStatus - percentage thresholds
   getComputingUnitCpuLimitUnit, isComputingUnitShmTooLarge (including mixed Mi/Gi comparisons), getJvmMemorySliderConfig, and buildLocalComputingUnitUri
   No production code was modified.
   
   Note: the issue lists a findNearestValidStep function that does not exist in the current codebase, so it was omitted; the actual exported functions are covered.
   
   ### Any related issues, documentation, discussions?
   Closes #6253
   
   ### How was this PR tested?
   Added 34 unit tests in the new spec file, all passing via ng test:
   
   cd frontend && npx ng test --watch=false --include='**/computing-unit.util.spec.ts'
   
   ✓ src/app/common/util/computing-unit.util.spec.ts (34 tests) 10ms
    Test Files - 1, passed (1)
         Tests - 34, passed (34)
   
   ### Was this PR authored or co-authored using generative AI tooling?
   Co-authored with Claude Opus 4.8 in compliance with ASF


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@texera.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] test(frontend): add unit tests for computing-unit.util resource helpers [texera]

Posted by "PG1204 (via GitHub)" <gi...@apache.org>.
PG1204 commented on PR #6435:
URL: https://github.com/apache/texera/pull/6435#issuecomment-4975769456

   /request-review @aglinxinyuan 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@texera.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] test(frontend): add unit tests for computing-unit.util resource helpers [texera]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #6435:
URL: https://github.com/apache/texera/pull/6435#discussion_r3583866467


##########
frontend/src/app/common/util/computing-unit.util.spec.ts:
##########
@@ -0,0 +1,241 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import { DashboardWorkflowComputingUnit } from "../type/workflow-computing-unit";
+import {
+  parseResourceUnit,
+  parseResourceNumber,
+  cpuResourceConversion,
+  memoryResourceConversion,
+  cpuPercentage,
+  memoryPercentage,
+  validateName,
+  getComputingUnitBadgeColor,
+  getComputingUnitStatusTooltip,
+  getComputingUnitCpuStatus,
+  getComputingUnitMemoryStatus,
+  getComputingUnitCpuLimitUnit,
+  isComputingUnitShmTooLarge,
+  getJvmMemorySliderConfig,
+  buildLocalComputingUnitUri,
+} from "./computing-unit.util";
+
+describe("parseResourceUnit", () => {
+  it("should extract the unit from a resource string", () => {
+    expect(parseResourceUnit("500Mi")).toBe("Mi");
+    expect(parseResourceUnit("2Gi")).toBe("Gi");
+    expect(parseResourceUnit("1000m")).toBe("m");
+  });
+
+  it("should return an empty string for a unitless number", () => {
+    expect(parseResourceUnit("2")).toBe("");
+    expect(parseResourceUnit("1.5")).toBe("");
+  });
+
+  it('should return "NaN" for empty or "NaN" input', () => {
+    expect(parseResourceUnit("")).toBe("NaN");
+    expect(parseResourceUnit("NaN")).toBe("NaN");
+  });
+
+  it("should return an empty string for a value that does not match the pattern", () => {
+    expect(parseResourceUnit("abc")).toBe("");
+  });
+});
+
+describe("parseResourceNumber", () => {
+  it("should extract the numeric value from a resource string", () => {
+    expect(parseResourceNumber("2Gi")).toBe(2);
+    expect(parseResourceNumber("500Mi")).toBe(500);
+  });
+
+  it("should handle decimal values", () => {
+    expect(parseResourceNumber("1.5Gi")).toBe(1.5);
+  });
+
+  it("should return 0 for empty, invalid, or NaN input", () => {
+    expect(parseResourceNumber("")).toBe(0);
+    expect(parseResourceNumber("NaN")).toBe(0);
+    expect(parseResourceNumber("abc")).toBe(0);
+  });
+});
+
+describe("cpuResourceConversion", () => {
+  it("should convert millicores to cores with 4 decimals", () => {
+    expect(cpuResourceConversion("1000m", "")).toBe("1.0000");
+    expect(cpuResourceConversion("500m", "")).toBe("0.5000");
+  });
+
+  it("should convert cores to millicores with 2 decimals", () => {
+    expect(cpuResourceConversion("2", "m")).toBe("2000.00");
+  });
+
+  it("should round to whole numbers for smaller units", () => {
+    expect(cpuResourceConversion("1", "u")).toBe("1000000");
+  });
+});
+
+describe("memoryResourceConversion", () => {
+  it("should convert between memory units with 4 decimals", () => {
+    expect(memoryResourceConversion("1Gi", "Gi")).toBe("1.0000");
+    expect(memoryResourceConversion("1024Mi", "Gi")).toBe("1.0000");
+    expect(memoryResourceConversion("512Mi", "Gi")).toBe("0.5000");
+  });
+});
+
+describe("cpuPercentage", () => {
+  it('should return 0 when usage or limit is "N/A"', () => {
+    expect(cpuPercentage("N/A", "1000m")).toBe(0);
+    expect(cpuPercentage("500m", "N/A")).toBe(0);
+  });
+
+  it("should return 0 when the limit is not positive", () => {
+    expect(cpuPercentage("500m", "0")).toBe(0);
+  });
+
+  it("should compute the usage percentage", () => {
+    expect(cpuPercentage("500m", "1000m")).toBe(50);
+  });
+
+  it("should clamp the percentage at 100", () => {
+    expect(cpuPercentage("2000m", "1000m")).toBe(100);
+  });
+});
+
+describe("memoryPercentage", () => {
+  it('should return 0 when usage or limit is "N/A"', () => {
+    expect(memoryPercentage("N/A", "1Gi")).toBe(0);
+    expect(memoryPercentage("512Mi", "N/A")).toBe(0);
+  });
+
+  it("should compute the usage percentage", () => {
+    expect(memoryPercentage("512Mi", "1Gi")).toBe(50);
+  });
+
+  it("should clamp the percentage at 100", () => {
+    expect(memoryPercentage("2Gi", "1Gi")).toBe(100);
+  });
+});

Review Comment:
   `memoryPercentage` includes a `limitValue <= 0` guard, and the PR description claims this behavior is covered, but the spec currently doesn’t test the non-positive-limit case. Adding a regression-style test will better pin the contract and align with the stated coverage.



##########
frontend/src/app/common/util/computing-unit.util.spec.ts:
##########
@@ -0,0 +1,241 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import { DashboardWorkflowComputingUnit } from "../type/workflow-computing-unit";

Review Comment:
   This import is only used as a type (in `as unknown as DashboardWorkflowComputingUnit` casts). Use a type-only import to avoid introducing an unnecessary runtime dependency during tests (and to match the codebase’s existing pattern of `import type` in spec files).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@texera.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] test(frontend): add unit tests for computing-unit.util resource helpers [texera]

Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #6435:
URL: https://github.com/apache/texera/pull/6435#issuecomment-4975840120

   ## [Codecov](https://app.codecov.io/gh/apache/texera/pull/6435?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   :white_check_mark: All modified and coverable lines are covered by tests.
   :white_check_mark: Project coverage is 70.00%. Comparing base ([`2e5c99c`](https://app.codecov.io/gh/apache/texera/commit/2e5c99c77ef53b1ed2dc0548e31d5313da1d4daf?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`b3c363d`](https://app.codecov.io/gh/apache/texera/commit/b3c363d3ff83b2b6c90dea3ee96e6f932bd5c37b?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   ```diff
   @@             Coverage Diff              @@
   ##               main    #6435      +/-   ##
   ============================================
   + Coverage     69.89%   70.00%   +0.10%     
     Complexity     3380     3380              
   ============================================
     Files          1142     1142              
     Lines         44844    44844              
     Branches       4949     4949              
   ============================================
   + Hits          31345    31393      +48     
   + Misses        11849    11803      -46     
   + Partials       1650     1648       -2     
   ```
   
   | [Flag](https://app.codecov.io/gh/apache/texera/pull/6435/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | | *Carryforward flag |
   |---|---|---|---|
   | [access-control-service](https://app.codecov.io/gh/apache/texera/pull/6435/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `70.00% <ø> (ø)` | | Carriedforward from [2e5c99c](https://app.codecov.io/gh/apache/texera/commit/2e5c99c77ef53b1ed2dc0548e31d5313da1d4daf?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [agent-service](https://app.codecov.io/gh/apache/texera/pull/6435/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `76.76% <ø> (ø)` | | Carriedforward from [2e5c99c](https://app.codecov.io/gh/apache/texera/commit/2e5c99c77ef53b1ed2dc0548e31d5313da1d4daf?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [amber](https://app.codecov.io/gh/apache/texera/pull/6435/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `66.65% <ø> (ø)` | | Carriedforward from [2e5c99c](https://app.codecov.io/gh/apache/texera/commit/2e5c99c77ef53b1ed2dc0548e31d5313da1d4daf?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [computing-unit-managing-service](https://app.codecov.io/gh/apache/texera/pull/6435/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `9.97% <ø> (ø)` | | Carriedforward from [2e5c99c](https://app.codecov.io/gh/apache/texera/commit/2e5c99c77ef53b1ed2dc0548e31d5313da1d4daf?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [config-service](https://app.codecov.io/gh/apache/texera/pull/6435/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `52.30% <ø> (ø)` | | Carriedforward from [2e5c99c](https://app.codecov.io/gh/apache/texera/commit/2e5c99c77ef53b1ed2dc0548e31d5313da1d4daf?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [file-service](https://app.codecov.io/gh/apache/texera/pull/6435/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `63.97% <ø> (ø)` | | Carriedforward from [2e5c99c](https://app.codecov.io/gh/apache/texera/commit/2e5c99c77ef53b1ed2dc0548e31d5313da1d4daf?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [frontend](https://app.codecov.io/gh/apache/texera/pull/6435/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `68.57% <ø> (+0.24%)` | :arrow_up: | |
   | [notebook-migration-service](https://app.codecov.io/gh/apache/texera/pull/6435/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `78.94% <ø> (ø)` | | Carriedforward from [2e5c99c](https://app.codecov.io/gh/apache/texera/commit/2e5c99c77ef53b1ed2dc0548e31d5313da1d4daf?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [pyamber](https://app.codecov.io/gh/apache/texera/pull/6435/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `91.19% <ø> (ø)` | | Carriedforward from [2e5c99c](https://app.codecov.io/gh/apache/texera/commit/2e5c99c77ef53b1ed2dc0548e31d5313da1d4daf?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [workflow-compiling-service](https://app.codecov.io/gh/apache/texera/pull/6435/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `55.14% <ø> (ø)` | | Carriedforward from [2e5c99c](https://app.codecov.io/gh/apache/texera/commit/2e5c99c77ef53b1ed2dc0548e31d5313da1d4daf?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   
   *This pull request uses carry forward flags. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) to find out more.
   </details>
   
   [:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/texera/pull/6435?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   <details><summary> :rocket: New features to boost your workflow: </summary>
   
   - :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
   </details>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@texera.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] test(frontend): add unit tests for computing-unit.util resource helpers [texera]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #6435:
URL: https://github.com/apache/texera/pull/6435#issuecomment-4975768339

   <!-- texera-reviewer-suggestion -->
   ### Automated Reviewer Suggestions
   
   Based on the `git blame` history of the changed files, we recommend the following reviewers:
   
   - No candidates found from `git blame` history.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@texera.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] test(frontend): add unit tests for computing-unit.util resource helpers [texera]

Posted by "aglinxinyuan (via GitHub)" <gi...@apache.org>.
aglinxinyuan merged PR #6435:
URL: https://github.com/apache/texera/pull/6435


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@texera.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org