Skip to content

Commit 468915d

Browse files
MTarek165brian-mulier-p
authored andcommitted
feat(tests): add test coverage for replaying LoopUntil
1 parent 035a92f commit 468915d

File tree

2 files changed

+33
-10
lines changed

2 files changed

+33
-10
lines changed

core/src/test/java/io/kestra/core/runners/AbstractRunnerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ protected void restartFailedWithAfterExecution() throws Exception {
193193

194194
@Test
195195
@LoadFlows({"flows/valids/loop-until-restart.yaml"})
196-
protected void restartLoopUntil() throws Exception{
197-
restartCaseTest.restartLoopUntil();
196+
protected void restartOrReplayLoopUntil() throws Exception{
197+
restartCaseTest.restartOrReplayLoopUntil();
198198
}
199199

200200
@Test

core/src/test/java/io/kestra/core/runners/RestartCaseTest.java

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -286,13 +286,13 @@ public void restartFailedWithAfterExecution() throws Exception {
286286
}
287287

288288

289-
public void restartLoopUntil() throws Exception{
289+
public void restartOrReplayLoopUntil() throws Exception{
290290
Flow flow = flowRepository.findById(MAIN_TENANT, "io.kestra.tests", "loop-until-restart").orElseThrow();
291291

292292
Execution firstExecution = runnerUtils.runOne(MAIN_TENANT, flow.getNamespace(), flow.getId(), Duration.ofSeconds(60));
293293

294294
assertThat(firstExecution.getState().getCurrent()).isEqualTo(Type.FAILED);
295-
295+
// restarting case
296296
Execution restartedExecution = executionService.restart(firstExecution, null);
297297
assertThat(restartedExecution).isNotNull();
298298
assertThat(restartedExecution.getId()).isEqualTo(firstExecution.getId());
@@ -301,14 +301,37 @@ public void restartLoopUntil() throws Exception{
301301
Execution finalRestartedExecution = runnerUtils.restartExecution( execution -> execution.getState().isFailed(), restartedExecution);
302302
assertThat(finalRestartedExecution.getState().getCurrent()).isEqualTo(Type.FAILED);
303303

304-
Optional<TaskRun> parentTaskRun = finalRestartedExecution.findTaskRunsByTaskId("loop_test").stream().findFirst();
305-
assertThat(parentTaskRun.isPresent());
304+
Optional<TaskRun> parentTaskRun1 = finalRestartedExecution.findTaskRunsByTaskId("loop_test").stream().findFirst();
305+
assertThat(parentTaskRun1.isPresent());
306306

307-
State.History lastFailed = parentTaskRun.get().getState().getHistories().getLast();
308-
State.History lastRestarted = parentTaskRun.get().getState().getHistories().reversed().stream()
307+
State.History lastFailed1 = parentTaskRun1.get().getState().getHistories().getLast();
308+
State.History lastRestarted1 = parentTaskRun1.get().getState().getHistories().reversed().stream()
309309
.filter(history -> history.getState() == Type.RESTARTED).findFirst().get();
310-
assertThat(lastRestarted).isNotNull();
311-
assertThat(lastRestarted.getDate().plus(10, ChronoUnit.SECONDS).isBefore(lastFailed.getDate()));
310+
assertThat(lastRestarted1).isNotNull();
311+
assertThat(lastRestarted1.getDate().plus(10, ChronoUnit.SECONDS).isBefore(lastFailed1.getDate()));
312+
313+
// replaying case
314+
Execution replayedExecution = executionService.replay(firstExecution, firstExecution.findTaskRunByTaskIdAndValue("loop_test", List.of()).getId(), null);
315+
assertThat(replayedExecution.getState().getCurrent()).isEqualTo(Type.RESTARTED);
316+
assertThat(replayedExecution.getId()).isNotEqualTo(firstExecution.getId());
317+
318+
Execution finalReplayedExecution = runnerUtils.awaitChildExecution(
319+
flow,
320+
firstExecution,
321+
replayedExecution,
322+
Duration.ofSeconds(60)
323+
);
324+
assertThat(finalReplayedExecution.getState().getCurrent()).isEqualTo(Type.FAILED);
325+
326+
Optional<TaskRun> parentTaskRun2 = finalReplayedExecution.findTaskRunsByTaskId("loop_test").stream().findFirst();
327+
assertThat(parentTaskRun2.isPresent());
328+
329+
State.History lastFailed2 = parentTaskRun2.get().getState().getHistories().getLast();
330+
State.History lastRestarted2 = parentTaskRun2.get().getState().getHistories().reversed().stream()
331+
.filter(history -> history.getState() == Type.RESTARTED).findFirst().get();
332+
assertThat(lastRestarted2).isNotNull();
333+
assertThat(lastRestarted2.getDate().plus(10, ChronoUnit.SECONDS).isBefore(lastFailed2.getDate()));
334+
312335
}
313336

314337
}

0 commit comments

Comments
 (0)