Copilot commented on code in PR #6756:
URL: https://github.com/apache/texera/pull/6756#discussion_r3627635005
##########
frontend/src/app/workspace/component/power-button/computing-unit-selection.component.spec.ts:
##########
@@ -1411,4 +1411,125 @@ describe("PowerButtonComponent", () => {
}
});
});
+
+ describe("resource-formatting and status getters", () => {
+ it("returns fallbacks when no unit is selected", () => {
+ component.selectedComputingUnit = null;
+ expect(component.getButtonText()).toBe("Connect");
+ expect(component.computeStatus()).toBe("processing");
Review Comment:
This newly added describe block duplicates several existing test sections in
this same spec file (e.g., "status helpers" around lines ~939-979, "resource
display getters" around ~1295-1337, "trackBy helpers" around ~1339-1347, and
"isCreateDisabled" around ~761-783). Keeping both sets increases maintenance
cost and makes future behavior changes require updating multiple places.
Consider trimming this block down to only the genuinely new edge cases
(e.g., cpuLimit="500m"/memoryLimit with no unit, and non-zero metrics ->
percentage/status), and rely on the earlier tests for the already-covered
behaviors.
##########
frontend/src/app/workspace/component/power-button/computing-unit-selection.component.spec.ts:
##########
@@ -1411,4 +1411,125 @@ describe("PowerButtonComponent", () => {
}
});
});
+
+ describe("resource-formatting and status getters", () => {
+ it("returns fallbacks when no unit is selected", () => {
+ component.selectedComputingUnit = null;
+ expect(component.getButtonText()).toBe("Connect");
+ expect(component.computeStatus()).toBe("processing");
+ expect(component.isComputingUnitRunning()).toBe(false);
+ expect(component.getGpuLimit()).toBe("NaN");
+ expect(component.getJvmMemorySize()).toBe("NaN");
+ expect(component.getSharedMemorySize()).toBe("NaN");
+ expect(component.getCpuValue()).toBe(0);
+ expect(component.getMemoryValue()).toBe(0);
+ });
+
+ it("reflects the selected unit's name and running state", () => {
+ component.selectedComputingUnit = makeComputingUnit({ name: "my-unit",
status: "Running" });
+ expect(component.getButtonText()).toBe("my-unit");
+ expect(component.isComputingUnitRunning()).toBe(true);
+ expect(component.computeStatus()).toBe("success");
+ });
+
+ it("maps the unit status to a computeStatus tag", () => {
+ component.selectedComputingUnit = makeComputingUnit({ status: "Pending"
});
+ expect(component.computeStatus()).toBe("warning");
+ component.selectedComputingUnit = makeComputingUnit({ status:
"Terminating" });
+ expect(component.computeStatus()).toBe("warning");
+ component.selectedComputingUnit = makeComputingUnit({ status: "Failed"
});
+ expect(component.computeStatus()).toBe("error");
+ expect(component.isComputingUnitRunning()).toBe(false);
+ });
+
+ it("passes through the raw gpu / jvm / shared-memory resource strings", ()
=> {
+ const unit = makeComputingUnit();
+ unit.computingUnit.resource.gpuLimit = "2";
+ unit.computingUnit.resource.jvmMemorySize = "512Mi";
+ unit.computingUnit.resource.shmSize = "128Mi";
+ component.selectedComputingUnit = unit;
+ expect(component.getGpuLimit()).toBe("2");
+ expect(component.getJvmMemorySize()).toBe("512Mi");
+ expect(component.getSharedMemorySize()).toBe("128Mi");
+ });
+
+ it("parses the numeric cpu / memory limits", () => {
+ const unit = makeComputingUnit();
+ unit.computingUnit.resource.cpuLimit = "4";
+ unit.computingUnit.resource.memoryLimit = "8Gi";
+ component.selectedComputingUnit = unit;
+ expect(component.getCpuLimit()).toBe(4);
+ expect(component.getMemoryLimit()).toBe(8);
+ });
+
+ it("derives display units, mapping the empty cpu unit to Cores and empty
memory unit to B", () => {
+ const unit = makeComputingUnit();
+ unit.computingUnit.resource.cpuLimit = "4"; // no unit -> "CPU" ->
"Cores"
+ unit.computingUnit.resource.memoryLimit = "8Gi";
+ component.selectedComputingUnit = unit;
+ expect(component.getCpuLimitUnit()).toBe("CPU");
+ expect(component.getCpuUnit()).toBe("Cores");
+ expect(component.getMemoryLimitUnit()).toBe("Gi");
+ expect(component.getMemoryUnit()).toBe("Gi");
+
+ unit.computingUnit.resource.cpuLimit = "500m";
+ unit.computingUnit.resource.memoryLimit = "1024"; // no unit -> "" -> "B"
+ expect(component.getCpuUnit()).toBe("m");
+ expect(component.getMemoryUnit()).toBe("B");
+ });
+
+ it("reports 0% usage and a success status when metrics are N/A", () => {
+ component.selectedComputingUnit = makeComputingUnit();
+ expect(component.getCpuPercentage()).toBe(0);
+ expect(component.getMemoryPercentage()).toBe(0);
+ expect(component.getCpuStatus()).toBe("success");
+ expect(component.getMemoryStatus()).toBe("success");
+ });
+
+ it("computes cpu usage as a percentage of the limit when metrics are
present", () => {
+ const unit = makeComputingUnit();
+ unit.computingUnit.resource.cpuLimit = "1"; // 1 core
+ unit.metrics.cpuUsage = "600m"; // 0.6 core
+ component.selectedComputingUnit = unit;
+ expect(component.getCpuPercentage()).toBe(60);
Review Comment:
This assertion is potentially brittle due to floating-point arithmetic (60
can become 59.999999999... depending on intermediate conversions). Using a
close-to matcher avoids flaky failures while still validating the intended
behavior.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]