PG1204 commented on code in PR #8552:
URL: https://github.com/apache/texera/pull/8552#discussion_r4057615728


##########
frontend/src/app/workspace/service/heatmap/heatmap-stats-restore.service.spec.ts:
##########
@@ -0,0 +1,295 @@
+/**
+ * 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 { TestBed } from "@angular/core/testing";
+import { Subject, of, throwError } from "rxjs";
+import type { Mocked } from "vitest";
+import { HeatmapStatsRestoreService } from "./heatmap-stats-restore.service";
+import { savePersistedHeatmapView } from "./heatmap-overlay-persistence";
+import { HeatmapView } from "./heatmap-scoring";
+import { WorkflowExecutionsService } from 
"../../../dashboard/service/user/workflow-executions/workflow-executions.service";
+import { WorkflowActionService } from 
"../workflow-graph/model/workflow-action.service";
+import { WorkflowStatusService } from 
"../workflow-status/workflow-status.service";
+import { ExecuteWorkflowService } from 
"../execute-workflow/execute-workflow.service";
+import { ExecutionState, OperatorState } from 
"../../types/execute-workflow.interface";
+import { WorkflowExecutionsEntry } from 
"../../../dashboard/type/workflow-executions-entry";
+import { WorkflowRuntimeStatistics } from 
"../../../dashboard/type/workflow-runtime-statistics";
+
+function makeExecution(overrides: Partial<WorkflowExecutionsEntry>): 
WorkflowExecutionsEntry {
+  return {
+    eId: 1,
+    vId: 1,
+    cuId: 7,
+    whId: null,
+    sId: 0,
+    userName: "user",
+    avatar: "",
+    name: "run",
+    startingTime: 1_000,
+    completionTime: 2_000,
+    status: 3, // Completed
+    result: "",
+    bookmarked: false,
+    logLocation: "",
+    ...overrides,
+  };
+}
+
+function makeStatsRow(overrides: Partial<WorkflowRuntimeStatistics>): 
WorkflowRuntimeStatistics {
+  return {
+    operatorId: "op1",
+    timestamp: 1_000,
+    inputTupleCount: 10,
+    inputTupleSize: 100,
+    outputTupleCount: 5,
+    outputTupleSize: 50,
+    totalDataProcessingTime: 1_000_000,
+    totalControlProcessingTime: 2_000,
+    totalIdleTime: 3_000,
+    numberOfWorkers: 2,
+    status: 3,
+    ...overrides,
+  };
+}
+
+describe("HeatmapStatsRestoreService", () => {
+  let service: HeatmapStatsRestoreService;
+  let executionsService: Mocked<WorkflowExecutionsService>;
+  let statusService: Mocked<WorkflowStatusService>;
+  let actionService: Mocked<WorkflowActionService>;
+  let executeService: Mocked<ExecuteWorkflowService>;
+  let statisticsUpdates: Subject<Record<string, never>>;
+
+  beforeEach(() => {
+    localStorage.clear();
+    // Default arrangement: overlay persisted on, a saved workflow, no live 
run.
+    savePersistedHeatmapView(HeatmapView.Runtime);
+
+    executionsService = {
+      retrieveWorkflowExecutions: vi.fn(() => of([makeExecution({})])),
+      retrieveWorkflowRuntimeStatistics: vi.fn(() => of([makeStatsRow({})])),
+    } as unknown as Mocked<WorkflowExecutionsService>;
+    actionService = {
+      getWorkflowMetadata: vi.fn(() => ({ wid: 42 })),
+    } as unknown as Mocked<WorkflowActionService>;
+    // A plain Subject, like the real one: subscribing does not emit, so it 
only cuts the
+    // restore short when another producer actually writes statistics.
+    statisticsUpdates = new Subject<Record<string, never>>();
+    statusService = {
+      setExternalStatus: vi.fn(),
+      getStatisticsUpdateStream: vi.fn(() => statisticsUpdates.asObservable()),

Review Comment:
   Added the spec where you suggested.
   
   Ran the thought experiment: with statisticsSubject swapped to a 
BehaviorSubject, every restore-service spec still passes, over-firing guard 
included. The double insulates it exactly as you describe.
   
   One correction: workflow-status.service.spec.ts does catch that swap today, 
5 of its specs fail under it. But only incidentally, on lengths and ordering 
shifted by the extra emission and none of them names the property. The new spec 
is the only one that fails for the stated reason.



-- 
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]

Reply via email to