Skip to content

Commit

Permalink
Merge pull request #197 from conductor-oss/decider_completion_logic_test
Browse files Browse the repository at this point in the history
Adds Test for Decider completion logic
  • Loading branch information
v1r3n authored Jul 2, 2024
2 parents 17b790e + 5596acf commit 8f10dce
Showing 1 changed file with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1242,6 +1242,55 @@ public void testCheckForWorkflowCompletion() {
assertTrue(deciderService.checkForWorkflowCompletion(workflow));
}

@Test
public void testWorkflowCompleted_WhenAllOptionalTasksInTerminalState() {
var workflowDef = createOnlyOptionalTaskWorkflow();

var workflow = new WorkflowModel();
workflow.setWorkflowDefinition(workflowDef);
workflow.setStatus(WorkflowModel.Status.RUNNING);

// Workflow should be running
assertFalse(deciderService.checkForWorkflowCompletion(workflow));

var task1 = new TaskModel();
task1.setTaskType(SIMPLE.name());
task1.setReferenceTaskName("o1");
task1.setStatus(TaskModel.Status.FAILED_WITH_TERMINAL_ERROR);

assertFalse(deciderService.checkForWorkflowCompletion(workflow));

var task2 = new TaskModel();
task2.setTaskType(SIMPLE.name());
task2.setReferenceTaskName("o2");
task2.setStatus(TaskModel.Status.COMPLETED_WITH_ERRORS);

workflow.getTasks().addAll(List.of(task1, task2));

// Workflow should be COMPLETED. All optional tasks have reached a terminal state.
assertTrue(deciderService.checkForWorkflowCompletion(workflow));
}

private WorkflowDef createOnlyOptionalTaskWorkflow() {
var workflowTask1 = new WorkflowTask();
workflowTask1.setName("junit_task_1");
workflowTask1.setTaskReferenceName("o1");
workflowTask1.setTaskDefinition(new TaskDef("junit_task_1"));
workflowTask1.setOptional(true);

var workflowTask2 = new WorkflowTask();
workflowTask2.setName("junit_task_2");
workflowTask2.setTaskReferenceName("o2");
workflowTask2.setTaskDefinition(new TaskDef("junit_task_2"));
workflowTask2.setOptional(true);

var workflowDef = new WorkflowDef();
workflowDef.setSchemaVersion(2);
workflowDef.setName("only_optional_tasks_workflow");
workflowDef.getTasks().addAll(Arrays.asList(workflowTask1, workflowTask2));
return workflowDef;
}

private WorkflowDef createConditionalWF() {

WorkflowTask workflowTask1 = new WorkflowTask();
Expand Down

0 comments on commit 8f10dce

Please sign in to comment.