spiff-arena/tests/SpiffWorkflow/bpmn/ParallelThroughSameTaskTest.py
Jon Herron 0892db6fa7 Squashed 'SpiffWorkflow/' content from commit 63db3e4
git-subtree-dir: SpiffWorkflow
git-subtree-split: 63db3e45947ec66b8d0efc2c74064004f8ff482c
2022-10-12 10:19:53 -04:00

180 lines
6.7 KiB
Python

# -*- coding: utf-8 -*-
import unittest
from SpiffWorkflow.task import TaskState
from SpiffWorkflow.bpmn.workflow import BpmnWorkflow
from tests.SpiffWorkflow.bpmn.BpmnWorkflowTestCase import BpmnWorkflowTestCase
__author__ = 'matth'
class ParallelThroughSameTaskTest(BpmnWorkflowTestCase):
def setUp(self):
spec, subprocesses = self.load_workflow_spec('Test-Workflows/Parallel-Through-Same-Task.bpmn20.xml', 'Parallel Through Same Task')
self.workflow = BpmnWorkflow(spec, subprocesses)
self.workflow.do_engine_steps()
def testRunThroughFirstRepeatTaskFirst(self):
self.assertEqual(2, len(self.workflow.get_tasks(TaskState.READY)))
self.do_next_named_step('Repeated Task')
self.workflow.do_engine_steps()
# The inclusive gateway allows this to pass through (since there is a
# route to it on the same sequence flow)
self.do_next_named_step('Done')
self.workflow.do_engine_steps()
self.do_next_named_step('Choice 1', choice='Yes')
self.workflow.do_engine_steps()
self.do_next_named_step('Yes Task')
self.workflow.do_engine_steps()
self.assertRaises(AssertionError, self.do_next_named_step, 'Done')
self.do_next_named_step('Repeated Task')
self.workflow.do_engine_steps()
self.do_next_named_step('Done')
self.workflow.do_engine_steps()
self.assertEqual(
0, len(self.workflow.get_tasks(TaskState.READY | TaskState.WAITING)))
def testRepeatTasksReadyTogether(self):
self.assertEqual(2, len(self.workflow.get_tasks(TaskState.READY)))
self.do_next_named_step('Choice 1', choice='Yes')
self.workflow.do_engine_steps()
self.do_next_named_step('Yes Task')
self.workflow.do_engine_steps()
self.assertRaises(AssertionError, self.do_next_named_step, 'Done')
ready_tasks = self.workflow.get_tasks(TaskState.READY)
self.assertEqual(2, len(ready_tasks))
self.assertEqual(
'Repeated Task', ready_tasks[0].task_spec.description)
ready_tasks[0].complete()
self.workflow.do_engine_steps()
# The inclusive gateway allows us through here, because there is no route for the other thread
# that doesn't use the same sequence flow
self.do_next_named_step('Done')
self.workflow.do_engine_steps()
self.do_next_named_step('Repeated Task')
self.workflow.do_engine_steps()
self.do_next_named_step('Done')
self.workflow.do_engine_steps()
self.assertEqual(
0, len(self.workflow.get_tasks(TaskState.READY | TaskState.WAITING)))
def testRepeatTasksReadyTogetherSaveRestore(self):
self.save_restore()
self.assertEqual(2, len(self.workflow.get_tasks(TaskState.READY)))
self.do_next_named_step('Choice 1', choice='Yes')
self.workflow.do_engine_steps()
self.save_restore()
self.do_next_named_step('Yes Task')
self.workflow.do_engine_steps()
self.save_restore()
self.assertRaises(AssertionError, self.do_next_named_step, 'Done')
ready_tasks = self.workflow.get_tasks(TaskState.READY)
self.assertEqual(2, len(ready_tasks))
self.assertEqual(
'Repeated Task', ready_tasks[0].task_spec.description)
ready_tasks[0].complete()
self.workflow.do_engine_steps()
self.save_restore()
# The inclusive gateway allows us through here, because there is no route for the other thread
# that doesn't use the same sequence flow
self.do_next_named_step('Done')
self.workflow.do_engine_steps()
self.save_restore()
self.do_next_named_step('Repeated Task')
self.workflow.do_engine_steps()
self.save_restore()
self.do_next_named_step('Done')
self.workflow.do_engine_steps()
self.save_restore()
self.assertEqual(
0, len(self.workflow.get_tasks(TaskState.READY | TaskState.WAITING)))
def testNoRouteRepeatTaskFirst(self):
self.save_restore()
self.assertEqual(2, len(self.workflow.get_tasks(TaskState.READY)))
self.do_next_named_step('Repeated Task')
self.workflow.do_engine_steps()
self.save_restore()
# The inclusive gateway allows this to pass through (since there is a
# route to it on the same sequence flow)
self.do_next_named_step('Done')
self.workflow.do_engine_steps()
self.save_restore()
self.do_next_named_step('Choice 1', choice='No')
self.workflow.do_engine_steps()
self.save_restore()
self.do_next_named_step('No Task')
self.workflow.do_engine_steps()
self.save_restore()
self.do_next_named_step('Done')
self.workflow.do_engine_steps()
self.save_restore()
self.assertEqual(
0, len(self.workflow.get_tasks(TaskState.READY | TaskState.WAITING)))
def testNoRouteNoTaskFirst(self):
self.save_restore()
self.assertEqual(2, len(self.workflow.get_tasks(TaskState.READY)))
self.do_next_named_step('Choice 1', choice='No')
self.workflow.do_engine_steps()
self.save_restore()
self.do_next_named_step('No Task')
self.workflow.do_engine_steps()
self.save_restore()
self.assertRaises(AssertionError, self.do_next_named_step, 'Done')
self.do_next_named_step('Repeated Task')
self.workflow.do_engine_steps()
self.save_restore()
self.do_next_named_step('Done')
self.workflow.do_engine_steps()
self.save_restore()
self.assertEqual(
0, len(self.workflow.get_tasks(TaskState.READY | TaskState.WAITING)))
def testNoRouteNoFirstThenRepeating(self):
self.save_restore()
self.assertEqual(2, len(self.workflow.get_tasks(TaskState.READY)))
self.do_next_named_step('Choice 1', choice='No')
self.workflow.do_engine_steps()
self.save_restore()
self.assertRaises(AssertionError, self.do_next_named_step, 'Done')
self.do_next_named_step('Repeated Task')
self.workflow.do_engine_steps()
self.save_restore()
self.assertRaises(AssertionError, self.do_next_named_step, 'Done')
self.do_next_named_step('No Task')
self.workflow.do_engine_steps()
self.save_restore()
self.do_next_named_step('Done')
self.workflow.do_engine_steps()
self.save_restore()
self.assertEqual(
0, len(self.workflow.get_tasks(TaskState.READY | TaskState.WAITING)))
def suite():
return unittest.TestLoader().loadTestsFromTestCase(ParallelThroughSameTaskTest)
if __name__ == '__main__':
unittest.TextTestRunner(verbosity=2).run(suite())