Yicong-Huang commented on code in PR #5922: URL: https://github.com/apache/texera/pull/5922#discussion_r3488788865
########## amber/src/test/scala/org/apache/texera/web/service/WorkflowExecutionServiceSpec.scala: ########## @@ -0,0 +1,112 @@ +/* + * 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. + */ + +package org.apache.texera.web.service + +import com.google.protobuf.timestamp.Timestamp +import org.apache.texera.amber.core.workflow.{WorkflowContext, WorkflowSettings} +import org.apache.texera.amber.core.workflowruntimestate.FatalErrorType.EXECUTION_FAILURE +import org.apache.texera.amber.core.workflowruntimestate.WorkflowFatalError +import org.apache.texera.amber.engine.architecture.rpc.controlreturns.WorkflowAggregatedState.RUNNING +import org.apache.texera.web.model.websocket.event.{ + TexeraWebSocketEvent, + WorkflowErrorEvent, + WorkflowStateEvent +} +import org.apache.texera.web.model.websocket.request.{LogicalPlanPojo, WorkflowExecuteRequest} +import org.apache.texera.web.storage.ExecutionStateStore +import org.scalatest.flatspec.AnyFlatSpec +import org.scalatest.matchers.should.Matchers + +import java.net.URI +import java.time.Instant +import scala.collection.mutable + +/** + * Regression guard for the consolidated init-error reporting path (#5921): + * `WorkflowExecutionService` registers its metadata-store diff handler at + * construction, so a fatalErrors update -- e.g. the one `errorHandler` records + * when `executeWorkflow` fails -- surfaces as a `WorkflowErrorEvent` through the + * normal websocket-event observable, with no separate pre-publish fallback. + * + * The unused `controllerConfig` / `resultService` are passed as `null` on + * purpose: construction must stay side-effect-free (all throwing work is in + * `executeWorkflow`), so a future change that dereferences them during + * construction would fail here. + */ +class WorkflowExecutionServiceSpec extends AnyFlatSpec with Matchers { + + private def buildService(store: ExecutionStateStore): WorkflowExecutionService = { + val request = WorkflowExecuteRequest( + executionName = "test", + engineVersion = "test", + logicalPlan = LogicalPlanPojo(List.empty, List.empty, List.empty, List.empty), + replayFromExecution = None, + workflowSettings = WorkflowSettings(), + emailNotificationEnabled = false, + computingUnitId = 0 + ) + new WorkflowExecutionService( + null, + new WorkflowContext(), + null, + request, + store, + (_: Throwable) => (), + None, + new URI("vfs:///test") + ) + } + + /** Subscribe to the metadata store's websocket-event stream and collect events. */ + private def collectEvents( + store: ExecutionStateStore + ): mutable.ArrayBuffer[TexeraWebSocketEvent] = { + val events = mutable.ArrayBuffer.empty[TexeraWebSocketEvent] + store.metadataStore.getWebsocketEventObservable.subscribe { + (evts: Iterable[TexeraWebSocketEvent]) => events ++= evts + } + events + } + + "WorkflowExecutionService" should + "surface a recorded fatal error as a WorkflowErrorEvent via the metadata-store handler" in { Review Comment: can we test error emitting at different phases can all be reported? -- 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]
