diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/routes/tasks_controller.py b/spiffworkflow-backend/src/spiffworkflow_backend/routes/tasks_controller.py index 70c24d14c..8576047d5 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/routes/tasks_controller.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/routes/tasks_controller.py @@ -350,7 +350,7 @@ def task_show(process_instance_id: int, task_guid: str = "next") -> flask.wrappe task.form_ui_schema = ui_form_contents _munge_form_ui_schema_based_on_hidden_fields_in_task_data(task) - _render_instructions_for_end_user(spiff_task, task) + _render_instructions_for_end_user(spiff_task, task) return make_response(jsonify(task), 200) diff --git a/spiffworkflow-backend/tests/spiffworkflow_backend/integration/test_for_good_errors.py b/spiffworkflow-backend/tests/spiffworkflow_backend/integration/test_for_good_errors.py index 90cbac876..51c27a6d1 100644 --- a/spiffworkflow-backend/tests/spiffworkflow_backend/integration/test_for_good_errors.py +++ b/spiffworkflow-backend/tests/spiffworkflow_backend/integration/test_for_good_errors.py @@ -3,6 +3,8 @@ from typing import Any from flask.app import Flask from flask.testing import FlaskClient + +from spiffworkflow_backend.routes.tasks_controller import _interstitial_stream from tests.spiffworkflow_backend.helpers.base_test import BaseTest from tests.spiffworkflow_backend.helpers.test_data import load_test_spec @@ -20,6 +22,10 @@ class TestForGoodErrors(BaseTest): client: FlaskClient, with_super_admin_user: UserModel, ) -> Any: + + # Call this to assure all engine-steps are fully processed before we search for human tasks. + _interstitial_stream(process_instance_id) + """Returns the next available user task for a given process instance, if possible.""" human_tasks = ( db.session.query(HumanTaskModel).filter(HumanTaskModel.process_instance_id == process_instance_id).all() diff --git a/spiffworkflow-backend/tests/spiffworkflow_backend/integration/test_process_api.py b/spiffworkflow-backend/tests/spiffworkflow_backend/integration/test_process_api.py index 778e1a8e4..7ce70e903 100644 --- a/spiffworkflow-backend/tests/spiffworkflow_backend/integration/test_process_api.py +++ b/spiffworkflow-backend/tests/spiffworkflow_backend/integration/test_process_api.py @@ -1588,7 +1588,8 @@ class TestProcessApi(BaseTest): f"/v1.0/process-instances/{self.modify_process_identifier_for_path_param(process_model_identifier)}/{process_instance_id}/run", headers=self.logged_in_headers(with_super_admin_user), ) - + # Call this to assure all engine-steps are fully processed. + _interstitial_stream(process_instance_id) assert response.json is not None assert response.json["next_task"] is not None @@ -2391,7 +2392,7 @@ class TestProcessApi(BaseTest): f"/v1.0/tasks/{process_instance_id}/{task_id}", headers=self.logged_in_headers(initiator_user), ) - assert response.status_code == 202 + assert response.status_code == 200 response = client.get( "/v1.0/tasks", diff --git a/spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_process_instance_processor.py b/spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_process_instance_processor.py index d0d4eb730..e9326363b 100644 --- a/spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_process_instance_processor.py +++ b/spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_process_instance_processor.py @@ -370,12 +370,13 @@ class TestProcessInstanceProcessor(BaseTest): ) assert top_level_subprocess_script_spiff_task is not None processor.resume() - processor.do_engine_steps(save=True) + processor.do_engine_steps(save=True, execution_strategy_name="greedy") assert len(process_instance.active_human_tasks) == 1 human_task_one = process_instance.active_human_tasks[0] spiff_manual_task = processor.bpmn_process_instance.get_task_from_id(UUID(human_task_one.task_id)) ProcessInstanceService.complete_form_task(processor, spiff_manual_task, {}, initiator_user, human_task_one) + processor.do_engine_steps(save=True, execution_strategy_name="greedy") assert process_instance.status == "complete" @@ -423,9 +424,11 @@ class TestProcessInstanceProcessor(BaseTest): process_instance = ProcessInstanceModel.query.filter_by(id=process_instance.id).first() processor = ProcessInstanceProcessor(process_instance) + processor.do_engine_steps(save=True, execution_strategy_name="greedy") human_task_one = process_instance.active_human_tasks[0] spiff_manual_task = processor.bpmn_process_instance.get_task_from_id(UUID(human_task_one.task_id)) ProcessInstanceService.complete_form_task(processor, spiff_manual_task, {}, initiator_user, human_task_one) + processor.do_engine_steps(save=True, execution_strategy_name="greedy") human_task_one = process_instance.active_human_tasks[0] spiff_manual_task = processor.bpmn_process_instance.get_task_from_id(UUID(human_task_one.task_id)) ProcessInstanceService.complete_form_task(processor, spiff_manual_task, {}, initiator_user, human_task_one) @@ -433,6 +436,7 @@ class TestProcessInstanceProcessor(BaseTest): # recreate variables to ensure all bpmn json was recreated from scratch from the db process_instance_relookup = ProcessInstanceModel.query.filter_by(id=process_instance.id).first() processor_final = ProcessInstanceProcessor(process_instance_relookup) + processor.do_engine_steps(save=True, execution_strategy_name="greedy") assert process_instance_relookup.status == "complete" data_set_1 = {"set_in_top_level_script": 1} @@ -544,6 +548,7 @@ class TestProcessInstanceProcessor(BaseTest): # assert task_model.python_env_data() == expected_python_env_data, message assert task_model.json_data() == expected_python_env_data, message + processor_final.do_engine_steps(save=True, execution_strategy_name="greedy") all_spiff_tasks = processor_final.bpmn_process_instance.get_tasks() assert len(all_spiff_tasks) > 1 for spiff_task in all_spiff_tasks: @@ -689,7 +694,7 @@ class TestProcessInstanceProcessor(BaseTest): process_model=process_model, user=initiator_user ) processor = ProcessInstanceProcessor(process_instance) - processor.do_engine_steps(save=True) + processor.do_engine_steps(save=True, execution_strategy_name="greedy") assert len(process_instance.active_human_tasks) == 1 assert len(process_instance.human_tasks) == 1 @@ -699,6 +704,7 @@ class TestProcessInstanceProcessor(BaseTest): ProcessInstanceService.complete_form_task(processor, spiff_task, {}, initiator_user, human_task_one) processor = ProcessInstanceProcessor(process_instance) + processor.do_engine_steps(save=True, execution_strategy_name="greedy") assert len(process_instance.active_human_tasks) == 1 assert len(process_instance.human_tasks) == 2 human_task_two = process_instance.active_human_tasks[0] @@ -707,6 +713,7 @@ class TestProcessInstanceProcessor(BaseTest): # ensure this does not raise a KeyError processor = ProcessInstanceProcessor(process_instance) + processor.do_engine_steps(save=True, execution_strategy_name="greedy") assert len(process_instance.active_human_tasks) == 1 assert len(process_instance.human_tasks) == 3 human_task_three = process_instance.active_human_tasks[0] diff --git a/spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_process_model.py b/spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_process_model.py index 40a9c96ee..d1b744848 100644 --- a/spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_process_model.py +++ b/spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_process_model.py @@ -43,7 +43,7 @@ class TestProcessModel(BaseTest): process_instance = self.create_process_instance_from_process_model(process_model) processor = ProcessInstanceProcessor(process_instance) - processor.do_engine_steps(save=True) + processor.do_engine_steps(save=True, execution_strategy_name="greedy") assert process_instance.status == "complete" def test_can_run_process_model_with_call_activities_when_not_in_same_directory( @@ -74,7 +74,7 @@ class TestProcessModel(BaseTest): ) process_instance = self.create_process_instance_from_process_model(process_model) processor = ProcessInstanceProcessor(process_instance) - processor.do_engine_steps(save=True) + processor.do_engine_steps(save=True, execution_strategy_name="greedy") assert process_instance.status == "complete" def test_can_run_process_model_with_call_activities_when_process_identifier_is_not_in_database( @@ -110,7 +110,7 @@ class TestProcessModel(BaseTest): db.session.query(SpecReferenceCache).delete() db.session.commit() processor = ProcessInstanceProcessor(process_instance) - processor.do_engine_steps(save=True) + processor.do_engine_steps(save=True, execution_strategy_name="greedy") assert process_instance.status == "complete" def test_extract_metadata(