diff --git a/mistral/tests/unit/engine1/test_policies.py b/mistral/tests/unit/engine1/test_policies.py index 5c2fc9346..617d937b0 100644 --- a/mistral/tests/unit/engine1/test_policies.py +++ b/mistral/tests/unit/engine1/test_policies.py @@ -21,6 +21,7 @@ from mistral import exceptions as exc from mistral.openstack.common import log as logging from mistral.services import scheduler from mistral.services import workbooks as wb_service +from mistral.services import workflows as wf_service from mistral.tests.unit.engine1 import base from mistral.workbook import parser as spec_parser @@ -535,3 +536,30 @@ class PoliciesTest(base.EngineTestCase): ) self.assertIn('Invalid data type in WaitBeforePolicy', str(exception)) + + def test_delayed_task_and_correct_finish_workflow(self): + wf_delayed_state = """--- + version: "2.0" + wf: + type: direct + tasks: + + task1: + action: std.noop + policies: + wait-before: 1 + + task2: + action: std.noop + """ + wf_service.create_workflows(wf_delayed_state) + + # Start workflow. + wf_ex = self.engine.start_workflow('wf', {}) + + self._await(lambda: self.is_execution_success(wf_ex.id)) + + # Note: We need to reread execution to access related tasks. + wf_ex = db_api.get_execution(wf_ex.id) + + self.assertEqual(2, len(wf_ex.task_executions)) diff --git a/mistral/workflow/base.py b/mistral/workflow/base.py index 56c462fcf..6a2a37dde 100644 --- a/mistral/workflow/base.py +++ b/mistral/workflow/base.py @@ -110,7 +110,7 @@ class WorkflowHandler(object): return [] - if not cmds and not wf_utils.find_running_tasks(self.wf_ex): + if not cmds and not wf_utils.find_incomplete_tasks(self.wf_ex): # If there are no running tasks at this point we can conclude that # the workflow has finished. if not self.is_paused_or_completed(): diff --git a/mistral/workflow/utils.py b/mistral/workflow/utils.py index b4dc91b0f..062520b4b 100644 --- a/mistral/workflow/utils.py +++ b/mistral/workflow/utils.py @@ -72,5 +72,10 @@ def find_successful_tasks(wf_ex): return [t for t in wf_ex.task_executions if t.state == states.SUCCESS] +def find_incomplete_tasks(wf_ex): + return [t for t in wf_ex.task_executions + if not states.is_completed(t.state)] + + def find_error_tasks(wf_ex): return [t for t in wf_ex.task_executions if t.state == states.ERROR]