@Override
  public State waitUntilFinish(Duration duration) {
    State state = delegate.waitUntilFinish(duration);
    this.terminalMetrics = delegate.metrics();
    this.terminalState = state;
    this.cancel.run();
    return state;
  }
@Test
  public void givenPipelineRunWithDuration_waitUntilFinish_reportsTerminalState() {
    PipelineResult delegate = mock(PipelineResult.class);
    when(delegate.waitUntilFinish(Duration.millis(3000L)))
        .thenReturn(PipelineResult.State.CANCELLED);
    PrismPipelineResult underTest = new PrismPipelineResult(delegate, exec::stop);
    assertThat(underTest.waitUntilFinish(Duration.millis(3000L)))
        .isEqualTo(PipelineResult.State.CANCELLED);
  }