public void terminate(
      WorkflowSummary workflowSummary,
      StepRuntimeSummary runtimeSummary,
      StepInstance.Status status) {
    try {
      StepRuntime.Result result =
          getStepRuntime(runtimeSummary.getType())
              .terminate(workflowSummary, cloneSummary(runtimeSummary));
      Checks.checkTrue(
          result.getState() == StepRuntime.State.STOPPED,
          "terminate call should return a STOPPED state in result: %s",
          result);
      runtimeSummary.mergeRuntimeUpdate(result.getTimeline(), result.getArtifacts());
      runtimeSummary.markTerminated(status, tracingManager);
    } catch (RuntimeException e) {
      metrics.counter(
          MetricConstants.STEP_RUNTIME_MANAGER_TERMINATE_EXCEPTION,
          getClass(),
          MetricConstants.STATUS_TAG,
          status.name());
      runtimeSummary.addTimeline(
          TimelineLogEvent.warn(
              "Failed to terminate the step %s of the workflow %s because [%s]",
              runtimeSummary.getIdentity(), workflowSummary.getIdentity(), e.getMessage()));
      throw e;
    }
  }
@Test
  public void testTerminate() {
    StepRuntimeSummary summary =
        StepRuntimeSummary.builder()
            .type(StepType.NOOP)
            .stepRetry(StepInstance.StepRetry.from(Defaults.DEFAULT_RETRY_POLICY))
            .build();
    runtimeManager.terminate(workflowSummary, summary, StepInstance.Status.STOPPED);
    assertEquals(StepInstance.Status.STOPPED, summary.getRuntimeState().getStatus());
    assertNotNull(summary.getRuntimeState().getEndTime());
    assertNotNull(summary.getRuntimeState().getModifyTime());
    assertEquals(1, summary.getPendingRecords().size());
    assertEquals(
        StepInstance.Status.NOT_CREATED, summary.getPendingRecords().get(0).getOldStatus());
    assertEquals(StepInstance.Status.STOPPED, summary.getPendingRecords().get(0).getNewStatus());
    assertEquals(artifact, summary.getArtifacts().get("test-artifact"));
    assertEquals(1, summary.getTimeline().getTimelineEvents().size());
    assertEquals("test termination", summary.getTimeline().getTimelineEvents().get(0).getMessage());
  }