From ad93b5fae6a29e55ccd78b4f48d080602470a814 Mon Sep 17 00:00:00 2001 From: Dan Date: Tue, 30 Nov 2021 12:44:35 -0500 Subject: [PATCH 1/3] We were not correctly handing the possibility of there only being a waiting task (and no ready tasks). We also had a problem with the validator throwing a 500 when it was trying tell us it would never finish validation. --- crc/services/workflow_processor.py | 8 ++++++++ crc/services/workflow_service.py | 15 +++++++++------ tests/workflow/test_workflow_processor.py | 14 ++++++++++++++ 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/crc/services/workflow_processor.py b/crc/services/workflow_processor.py index 715995a0..b06c04de 100644 --- a/crc/services/workflow_processor.py +++ b/crc/services/workflow_processor.py @@ -398,6 +398,14 @@ class WorkflowProcessor(object): # Get a list of all ready tasks ready_tasks = self.bpmn_workflow.get_tasks(SpiffTask.READY) + if len(ready_tasks) == 0: + # If no ready tasks exist, check for a waiting task. + waiting_tasks = self.bpmn_workflow.get_tasks(SpiffTask.WAITING) + if len(waiting_tasks) > 0: + return waiting_tasks[0] + else: + return # We have not tasks to return. + # Get a list of all completed user tasks (Non engine tasks) completed_user_tasks = self.completed_user_tasks() diff --git a/crc/services/workflow_service.py b/crc/services/workflow_service.py index 23edf646..6bfba31c 100755 --- a/crc/services/workflow_service.py +++ b/crc/services/workflow_service.py @@ -177,14 +177,17 @@ class WorkflowService(object): WorkflowService.populate_form_with_random_data(task, task_api, required_only) processor.complete_task(task) if test_until == task.task_spec.name: - raise ApiError.from_task("validation_break", - f"The validation has been exited early on task '{task.task_spec.name}' and was parented by ", - task.parent) + raise ApiError.from_task( + "validation_break", + f"The validation has been exited early on task '{task.task_spec.name}' " + f"and was parented by ", + task.parent) count += 1 if count >= 100: - raise ApiError.from_task(code='validation_loop', - message=f'There appears to be an infinite loop in the validation. Task is {task.task_spec.description}', - task=task) + raise ApiError(code='unending_validation', + message=f'There appears to be no way to complete this workflow,' + f' halting validation.') + WorkflowService._process_documentation(processor.bpmn_workflow.last_task.parent.parent) except WorkflowException as we: diff --git a/tests/workflow/test_workflow_processor.py b/tests/workflow/test_workflow_processor.py index d8ff97b8..a3b756fd 100644 --- a/tests/workflow/test_workflow_processor.py +++ b/tests/workflow/test_workflow_processor.py @@ -164,6 +164,20 @@ class TestWorkflowProcessor(BaseTest): self.assertIn("FactService", task.data) self.assertIsInstance(task.task_spec, EndEvent) + def test_workflow_processor_returns_waiting_task_if_no_ready_tasks_exist(self): + self.load_example_data() + workflow_spec_model = self.load_test_spec("timer_inline") + study = session.query(StudyModel).first() + processor = self.get_processor(study, workflow_spec_model) + processor.do_engine_steps() + task = processor.next_task() + task.data = {"type": "buzzword"} + processor.complete_task(task) + processor.do_engine_steps() + task = processor.next_task() + self.assertIsNotNone(task) + self.assertEqual(task.state, task.WAITING) + def test_workflow_validation_error_is_properly_raised(self): self.load_example_data() workflow_spec_model = self.load_test_spec("invalid_spec") From 676321c2e26e5efe2ef5ad1eb658e430d3657301 Mon Sep 17 00:00:00 2001 From: Dan Date: Tue, 30 Nov 2021 12:55:52 -0500 Subject: [PATCH 2/3] Fixing a test. --- tests/workflow/test_workflow_infinite_loop.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/workflow/test_workflow_infinite_loop.py b/tests/workflow/test_workflow_infinite_loop.py index 506f9eed..2cd91448 100644 --- a/tests/workflow/test_workflow_infinite_loop.py +++ b/tests/workflow/test_workflow_infinite_loop.py @@ -15,4 +15,4 @@ class TestWorkflowInfiniteLoop(BaseTest): spec_model = self.load_test_spec('infinite_loop') rv = self.app.get('/v1.0/workflow-specification/%s/validate' % spec_model.id, headers=self.logged_in_headers()) json_data = json.loads(rv.get_data(as_text=True)) - self.assertIn('There appears to be an infinite loop', json_data[0]['message']) + self.assertIn('There appears to be no way to complete this workflow, halting validation.', json_data[0]['message']) From cf3f8ce4445dbcf6228af1d4a8bbd7496b212a74 Mon Sep 17 00:00:00 2001 From: Dan Date: Tue, 30 Nov 2021 13:29:31 -0500 Subject: [PATCH 3/3] Missing the bpmns for a test. --- tests/data/timer_inline/timer_inline.bpmn | 68 +++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 tests/data/timer_inline/timer_inline.bpmn diff --git a/tests/data/timer_inline/timer_inline.bpmn b/tests/data/timer_inline/timer_inline.bpmn new file mode 100644 index 00000000..0de793ff --- /dev/null +++ b/tests/data/timer_inline/timer_inline.bpmn @@ -0,0 +1,68 @@ + + + + + Flow_1pahvlr + + + Flow_1pahvlr + Flow_1pvkgnu + + + Flow_1pvkgnu + Flow_1elbn9u + + timedelta(seconds=.25) + + + + Flow_1elbn9u + Flow_1ekgt3x + + + Flow_1ekgt3x + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +