This repository has been archived by the owner on Dec 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- fix correlationId for failure workflow - add failure taskId to input
- Loading branch information
Showing
5 changed files
with
325 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
146 changes: 146 additions & 0 deletions
146
...harness/src/test/groovy/com/netflix/conductor/test/integration/FailureWorkflowSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
/* | ||
* Copyright 2021 Netflix, Inc. | ||
* <p> | ||
* Licensed 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 | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* 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 com.netflix.conductor.test.integration | ||
|
||
import org.springframework.beans.factory.annotation.Autowired | ||
|
||
import com.netflix.conductor.common.metadata.tasks.Task | ||
import com.netflix.conductor.common.run.Workflow | ||
import com.netflix.conductor.core.execution.tasks.SubWorkflow | ||
import com.netflix.conductor.test.base.AbstractSpecification | ||
|
||
import spock.lang.Shared | ||
|
||
class FailureWorkflowSpec extends AbstractSpecification { | ||
|
||
@Shared | ||
def WORKFLOW_WITH_TERMINATE_TASK_FAILED = 'test_terminate_task_failed_wf' | ||
|
||
@Shared | ||
def PARENT_WORKFLOW_WITH_FAILURE_TASK = 'test_task_failed_parent_wf' | ||
|
||
@Autowired | ||
SubWorkflow subWorkflowTask | ||
|
||
def setup() { | ||
workflowTestUtil.registerWorkflows( | ||
'failure_workflow_for_terminate_task_workflow.json', | ||
'terminate_task_failed_workflow_integration.json', | ||
'test_task_failed_parent_workflow.json', | ||
'test_task_failed_sub_workflow.json' | ||
) | ||
} | ||
|
||
def "Test workflow with a task that failed"() { | ||
given: "workflow input" | ||
def workflowInput = new HashMap() | ||
workflowInput['a'] = 1 | ||
|
||
when: "Start the workflow which has the failed task" | ||
def testId = 'testId' | ||
def workflowInstanceId = workflowExecutor.startWorkflow(WORKFLOW_WITH_TERMINATE_TASK_FAILED, 1, | ||
testId, workflowInput, null, null, null) | ||
|
||
then: "Verify that the workflow has failed" | ||
with(workflowExecutionService.getExecutionStatus(workflowInstanceId, true)) { | ||
status == Workflow.WorkflowStatus.FAILED | ||
tasks.size() == 2 | ||
reasonForIncompletion.contains('Workflow is FAILED by TERMINATE task') | ||
tasks[0].status == Task.Status.COMPLETED | ||
tasks[0].taskType == 'LAMBDA' | ||
tasks[0].seq == 1 | ||
tasks[1].status == Task.Status.COMPLETED | ||
tasks[1].taskType == 'TERMINATE' | ||
tasks[1].seq == 2 | ||
output | ||
def failedWorkflowId = output['conductor.failure_workflow'] as String | ||
def workflowCorrelationId = correlationId | ||
def workflowFailureTaskId = tasks[1].taskId | ||
with(workflowExecutionService.getExecutionStatus(failedWorkflowId, true)) { | ||
status == Workflow.WorkflowStatus.COMPLETED | ||
correlationId == workflowCorrelationId | ||
input['workflowId'] == workflowInstanceId | ||
input['failureTaskId'] == workflowFailureTaskId | ||
tasks.size() == 1 | ||
tasks[0].taskType == 'LAMBDA' | ||
} | ||
} | ||
} | ||
|
||
def "Test workflow with a task failed in subworkflow"() { | ||
given: "workflow input" | ||
def workflowInput = new HashMap() | ||
workflowInput['a'] = 1 | ||
|
||
when: "Start the workflow which has the subworkflow task" | ||
def workflowInstanceId = workflowExecutor.startWorkflow(PARENT_WORKFLOW_WITH_FAILURE_TASK, 1, | ||
'', workflowInput, null, null, null) | ||
|
||
then: "verify that the workflow has started and the tasks are as expected" | ||
with(workflowExecutionService.getExecutionStatus(workflowInstanceId, true)) { | ||
status == Workflow.WorkflowStatus.RUNNING | ||
tasks.size() == 2 | ||
tasks[0].status == Task.Status.COMPLETED | ||
tasks[0].taskType == 'LAMBDA' | ||
tasks[0].referenceTaskName == 'lambdaTask1' | ||
tasks[0].seq == 1 | ||
tasks[1].status == Task.Status.SCHEDULED | ||
tasks[1].taskType == 'SUB_WORKFLOW' | ||
tasks[1].seq == 2 | ||
} | ||
|
||
when: "subworkflow is retrieved" | ||
def workflow = workflowExecutionService.getExecutionStatus(workflowInstanceId, true) | ||
def subWorkflowTaskId = workflow.getTaskByRefName("test_task_failed_sub_wf").getTaskId() | ||
asyncSystemTaskExecutor.execute(subWorkflowTask, subWorkflowTaskId) | ||
workflow = workflowExecutionService.getExecutionStatus(workflowInstanceId, true) | ||
def subWorkflowId = workflow.getTaskByRefName("test_task_failed_sub_wf").subWorkflowId | ||
|
||
then: "verify that the sub workflow has failed" | ||
with(workflowExecutionService.getExecutionStatus(subWorkflowId, true)) { | ||
status == Workflow.WorkflowStatus.FAILED | ||
tasks.size() == 2 | ||
reasonForIncompletion.contains('Workflow is FAILED by TERMINATE task') | ||
tasks[0].status == Task.Status.COMPLETED | ||
tasks[0].taskType == 'LAMBDA' | ||
tasks[0].seq == 1 | ||
tasks[1].status == Task.Status.COMPLETED | ||
tasks[1].taskType == 'TERMINATE' | ||
tasks[1].seq == 2 | ||
} | ||
|
||
then: "Verify that the workflow has failed and correct inputs passed into the failure workflow" | ||
with(workflowExecutionService.getExecutionStatus(workflowInstanceId, true)) { | ||
status == Workflow.WorkflowStatus.FAILED | ||
tasks.size() == 2 | ||
tasks[0].status == Task.Status.COMPLETED | ||
tasks[0].taskType == 'LAMBDA' | ||
tasks[0].referenceTaskName == 'lambdaTask1' | ||
tasks[0].seq == 1 | ||
tasks[1].status == Task.Status.FAILED | ||
tasks[1].taskType == 'SUB_WORKFLOW' | ||
tasks[1].seq == 2 | ||
def failedWorkflowId = output['conductor.failure_workflow'] as String | ||
def workflowCorrelationId = correlationId | ||
def workflowFailureTaskId = tasks[1].taskId | ||
with(workflowExecutionService.getExecutionStatus(failedWorkflowId, true)) { | ||
status == Workflow.WorkflowStatus.COMPLETED | ||
correlationId == workflowCorrelationId | ||
input['workflowId'] == workflowInstanceId | ||
input['failureTaskId'] == workflowFailureTaskId | ||
tasks.size() == 1 | ||
tasks[0].taskType == 'LAMBDA' | ||
} | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
test-harness/src/test/resources/test_task_failed_parent_workflow.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"name": "test_task_failed_parent_wf", | ||
"version": 1, | ||
"tasks": [ | ||
{ | ||
"name": "test_lambda_task1", | ||
"taskReferenceName": "lambdaTask1", | ||
"inputParameters": { | ||
"lambdaValue": "${workflow.input.lambdaValue}", | ||
"scriptExpression": "var i = 10; if ($.lambdaValue == 1){ return {testvalue: 'Lambda value was 1', iValue: i} } else { return {testvalue: 'Lambda value was NOT 1', iValue: i + 3} }" | ||
}, | ||
"type": "LAMBDA" | ||
}, | ||
{ | ||
"name": "test_task_failed_sub_wf", | ||
"taskReferenceName": "test_task_failed_sub_wf", | ||
"inputParameters": { | ||
}, | ||
"type": "SUB_WORKFLOW", | ||
"subWorkflowParam": { | ||
"name": "test_task_failed_sub_wf" | ||
} | ||
}, | ||
{ | ||
"name": "test_lambda_task2", | ||
"taskReferenceName": "lambdaTask2", | ||
"inputParameters": { | ||
"lambdaValue": "${workflow.input.lambdaValue}", | ||
"scriptExpression": "var i = 10; if ($.lambdaValue == 1){ return {testvalue: 'Lambda value was 1', iValue: i} } else { return {testvalue: 'Lambda value was NOT 1', iValue: i + 3} }" | ||
}, | ||
"type": "LAMBDA" | ||
} | ||
], | ||
"schemaVersion": 2, | ||
"ownerEmail": "test@harness.com", | ||
"failureWorkflow": "failure_workflow" | ||
} |
65 changes: 65 additions & 0 deletions
65
test-harness/src/test/resources/test_task_failed_sub_workflow.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
{ | ||
"name": "test_task_failed_sub_wf", | ||
"version": 1, | ||
"tasks": [ | ||
{ | ||
"name": "lambda", | ||
"taskReferenceName": "lambda0", | ||
"inputParameters": { | ||
"input": "${workflow.input}", | ||
"scriptExpression": "if ($.input.a==1){return {testvalue: true}} else{return {testvalue: false}}" | ||
}, | ||
"type": "LAMBDA", | ||
"decisionCases": {}, | ||
"defaultCase": [], | ||
"forkTasks": [], | ||
"startDelay": 0, | ||
"joinOn": [], | ||
"optional": false, | ||
"defaultExclusiveJoinTask": [], | ||
"asyncComplete": false, | ||
"loopOver": [] | ||
}, | ||
{ | ||
"name": "terminate", | ||
"taskReferenceName": "terminate0", | ||
"inputParameters": { | ||
"terminationStatus": "FAILED", | ||
"workflowOutput": "${lambda0.output}" | ||
}, | ||
"type": "TERMINATE", | ||
"decisionCases": {}, | ||
"defaultCase": [], | ||
"forkTasks": [], | ||
"startDelay": 0, | ||
"joinOn": [], | ||
"optional": false, | ||
"defaultExclusiveJoinTask": [], | ||
"asyncComplete": false, | ||
"loopOver": [] | ||
}, | ||
{ | ||
"name": "integration_task_2", | ||
"taskReferenceName": "t2", | ||
"inputParameters": {}, | ||
"type": "SIMPLE", | ||
"decisionCases": {}, | ||
"defaultCase": [], | ||
"forkTasks": [], | ||
"startDelay": 0, | ||
"joinOn": [], | ||
"optional": false, | ||
"defaultExclusiveJoinTask": [], | ||
"asyncComplete": false, | ||
"loopOver": [] | ||
} | ||
], | ||
"inputParameters": [], | ||
"outputParameters": {}, | ||
"schemaVersion": 2, | ||
"restartable": true, | ||
"workflowStatusListenerEnabled": false, | ||
"timeoutPolicy": "ALERT_ONLY", | ||
"timeoutSeconds": 0, | ||
"ownerEmail": "test@harness.com" | ||
} |