def test_reading_script_task(self) -> None: process = read_bpmn_file("test/adhesive/xml/script.bpmn") self.assertEqual(4, len(process.tasks)) self.assertEqual(3, len(process.edges)) self.assertEqual(1, len(process.start_events)) self.assertEqual(1, len(process.end_events)) self.assertTrue(isinstance(process.tasks["_3"], ScriptTask)) script_task: ScriptTask = cast(ScriptTask, process.tasks["_3"]) self.assertEqual("text/python", script_task.language) self.assertEqual( textwrap.dedent("""\ import uuid if not context.data.executions: context.data.executions = dict() if context.task.name not in context.data.executions: context.data.executions[context.task.name] = set() context.data.executions[context.task.name].add(str(uuid.uuid4()))""" ), script_task.script, )
def test_loop_execution_no_wait(self): adhesive.process.process = read_bpmn_file( "test/adhesive/xml/loop.bpmn") process_executor = ProcessExecutor(adhesive.process, wait_tasks=False) data = process_executor.execute() assert_equal_execution( { "Build Germanium Image on mac": 1, "Build Germanium Image on windows": 1, "Build Germanium Image on linux": 1, "Test Browser ie on linux": 1, "Cleanup Platform linux": 3, "Cleanup Platform windows": 3, "Cleanup Platform mac": 3, "Test Browser chrome on linux": 1, "Test Browser edge on linux": 1, "Test Browser edge on windows": 1, "Test Browser chrome on windows": 1, "Test Browser ie on windows": 1, "Test Browser chrome on mac": 1, "Test Browser edge on mac": 1, "Test Browser ie on mac": 1, }, data.executions, ) self.assertFalse(process_executor.events)
def test_reading_message_event(self) -> None: process = read_bpmn_file("test/adhesive/xml/message-event.bpmn") self.assertEqual(3, len(process.tasks)) self.assertEqual(2, len(process.edges)) self.assertEqual(0, len(process.start_events)) self.assertEqual(1, len(process.message_events)) self.assertEqual(1, len(process.end_events))
def test_reading_human_task(self) -> None: process = read_bpmn_file("test/adhesive/xml/user-task.bpmn") self.assertEqual(3, len(process.tasks)) self.assertEqual(2, len(process.edges)) self.assertEqual(1, len(process.start_events)) self.assertEqual(1, len(process.end_events)) self.assertTrue(isinstance(process.tasks["_3"], UserTask))
def test_reading_parallel_gateway_bpmn(self) -> None: process = read_bpmn_file("test/adhesive/xml/gateway-parallel.bpmn") self.assertEqual(9, len(process.tasks)) self.assertEqual(12, len(process.edges)) self.assertEqual(1, len(process.start_events)) self.assertEqual(1, len(process.end_events)) self.assertTrue(isinstance(process.tasks["_9"], ParallelGateway))
def test_reading_gateway_inclusive_sign_bpmn(self) -> None: process = read_bpmn_file("test/adhesive/xml/gateway-inclusive.bpmn") self.assertEqual(8, len(process.tasks)) self.assertEqual(10, len(process.edges)) self.assertEqual(1, len(process.start_events)) self.assertEqual(1, len(process.end_events)) self.assertTrue(isinstance(process.tasks["_3"], ParallelGateway))
def test_reading_gateway_complex(self) -> None: process = read_bpmn_file("test/adhesive/xml/gateway-complex.bpmn") self.assertEqual(8, len(process.tasks)) self.assertEqual(10, len(process.edges)) self.assertEqual(1, len(process.start_events)) self.assertEqual(1, len(process.end_events)) self.assertTrue(isinstance(process.tasks["_4"], ComplexGateway))
def bpmn_build( file_name: Union[str, IO[bytes], TextIO], ut_provider: Optional["UserTaskProvider"] = None, wait_tasks: bool = True, initial_data=None, ): """ Start a build that was described in BPMN """ process.process = read_bpmn_file(file_name) return _build(ut_provider=ut_provider, wait_tasks=wait_tasks, initial_data=initial_data)
def test_reading_loop(self) -> None: process = read_bpmn_file("test/adhesive/xml/loop.bpmn") self.assertEqual(5, len(process.tasks)) self.assertEqual(5, len(process.edges)) self.assertEqual(1, len(process.start_events)) self.assertEqual(1, len(process.end_events)) self.assertTrue(isinstance(process.tasks["_5"], Task)) loop = cast(ProcessTask, process.tasks["_5"]).loop assert loop self.assertEqual("data.test_platforms", loop.loop_expression)
def test_reading_exclusive_gateway_bpmn(self) -> None: process = read_bpmn_file("test/adhesive/xml/exclusive_gateway.bpmn") self.assertEqual(6, len(process.tasks)) self.assertEqual(6, len(process.edges)) self.assertEqual(1, len(process.start_events)) self.assertEqual(1, len(process.end_events)) task_route = process.edges["_9"] self.assertEqual('data.route == "task"', task_route.condition) task_route = process.edges["_10"] self.assertEqual("", task_route.condition)
def test_link_back_execution(self): adhesive.process.process = read_bpmn_file("test/adhesive/xml/link-back.bpmn") process_executor = ProcessExecutor(adhesive.process) data = process_executor.execute() assert_equal_execution( { "Increment X by 1": 5, "Build Germanium Image": 1, }, data.executions, ) self.assertFalse(process_executor.events)
def test_reading_event_timeouts(self) -> None: process = read_bpmn_file("test/adhesive/xml/event-timeout.bpmn") self.assertEqual(11, len(process.tasks)) self.assertEqual(9, len(process.edges)) self.assertEqual(1, len(process.start_events)) self.assertEqual(0, len(process.message_events)) self.assertEqual(2, len(process.end_events)) evented_task = cast(ProcessTask, process.tasks["_3"]) self.assertTrue(evented_task.timer_events) assert evented_task.timer_events self.assertEqual(5, len(evented_task.timer_events))
def test_reading_subprocess_bpmn(self) -> None: process = read_bpmn_file("test/adhesive/xml/adhesive_subprocess.bpmn") self.assertEqual(5, len(process.tasks)) self.assertEqual(4, len(process.edges)) self.assertEqual(1, len(process.start_events)) self.assertEqual(1, len(process.end_events)) subprocess = cast(SubProcess, process.tasks["_7"]) self.assertEqual("Test Browsers", subprocess.name) self.assertEqual(3, len(subprocess.tasks)) self.assertEqual(1, len(subprocess.edges)) self.assertEqual(2, len(subprocess.start_events)) self.assertEqual(2, len(subprocess.end_events))
def test_reading_bpmn(self) -> None: """ Try to see if reading a basic BPMN works. """ process = read_bpmn_file("test/adhesive/xml/adhesive.bpmn") self.assertEqual(6, len(process.tasks)) self.assertEqual(6, len(process.edges)) self.assertEqual(1, len(process.start_events)) self.assertEqual(1, len(process.end_events)) first_task = process.tasks["_3"] self.assertEqual("Build Germanium Image", first_task.name) self.assertTrue(process)
def test_link_back_execution(self): adhesive.process.process = read_bpmn_file( "test/adhesive/xml/user-task-join.bpmn" ) process_executor = ProcessExecutor( adhesive.process, ut_provider=TestUserTaskProvider() ) data = process_executor.execute() self.assertEqual("OK", data.OK) self.assertEqual("Cancel", data.Cancel) self.assertEqual("branch", data.branch) self.assertEqual("12.0", data.version) self.assertFalse(process_executor.events)
def test_basic_execution(self): """ Load a simple process and execute it. """ adhesive.process.process = read_bpmn_file( "test/adhesive/xml/adhesive-basic.bpmn") process_executor = ProcessExecutor(adhesive.process) data = process_executor.execute() assert_equal_execution( { "Build Germanium Image": 1, }, data.executions, ) self.assertFalse(process_executor.events)
def test_parallel_gateway_non_wait(self): """ Load a process with a gateway and test it.. """ adhesive.process.process = read_bpmn_file( "test/adhesive/xml/gateway-parallel.bpmn") process_executor = ProcessExecutor(adhesive.process) data = process_executor.execute() assert_equal_execution( { "Test Chrome": 3, "Build Germanium Image": 3, }, data.executions, ) self.assertFalse(process_executor.events)
def test_error_propagates_up(self): """ Load a process with a gateway and test it.. """ adhesive.process.process = read_bpmn_file( "test/adhesive/xml/error-event-subprocess-propagates-up.bpmn") process_executor = ProcessExecutor(adhesive.process) data = process_executor.execute() assert_equal_execution( { "Error Was Caught": 1, }, data.executions, ) self.assertFalse(process_executor.events)
def test_reading_error_event_interrupting(self) -> None: process = read_bpmn_file( "test/adhesive/xml/error-event-interrupting.bpmn") self.assertEqual(6, len(process.tasks)) self.assertEqual(5, len(process.edges)) self.assertEqual(1, len(process.start_events)) self.assertEqual(1, len(process.end_events)) boundary_event: ErrorBoundaryEvent = cast(ErrorBoundaryEvent, process.tasks["_6"]) self.assertTrue(isinstance(process.tasks["_6"], ErrorBoundaryEvent)) self.assertTrue(boundary_event.cancel_activity) self.assertFalse(boundary_event.parallel_multiple) parent_event: Task = cast(Task, process.tasks["_3"]) self.assertEqual(parent_event.error_task, boundary_event)
def test_log_redirection(self): """ Load a process with a gateway and test it.. """ adhesive.process.process = read_bpmn_file( "test/adhesive/xml/redirect-logs.bpmn") process_executor = ProcessExecutor(adhesive.process) data = process_executor.execute() assert_equal_execution( { "sh: echo hello world && echo bad world >&2 && echo good world": 1, "Store current execution id": 1, }, data.executions, ) self.assertFalse(process_executor.events) adhesive_temp_folder = config.current.temp_folder path_to_glob = os.path.join(adhesive_temp_folder, data.execution_id, "logs", "_4", "*", "stdout") log_path = glob.glob(path_to_glob) if not log_path: raise Exception( f"Unable to match any file for glob {path_to_glob}") with open(log_path[0], "rt") as f: self.assertEqual( f.read(), "sh: echo hello world && " "echo bad world >&2 && " "echo good world\nhello world\ngood world\n", ) log_path = glob.glob( os.path.join(adhesive_temp_folder, data.execution_id, "logs", "_4", "*", "stderr")) with open(log_path[0], "rt") as f: self.assertEqual(f.read(), "bad world\n")
def test_script_task_execution(self): adhesive.process.process = read_bpmn_file( "test/adhesive/xml/script.bpmn") process_executor = ProcessExecutor(adhesive.process) data = process_executor.execute() assert_equal_execution( { "Script Task": 1, "Build Germanium Image": 1, }, data.executions, ) self.assertFalse( process_executor.events, "Some events were not unregistered and/or executed.", )
def test_exclusive_gateway_non_wait(self): """ Load a process with a gateway and test it.. """ adhesive.process.process = read_bpmn_file( "test/adhesive/xml/gateway-exclusive-sign.bpmn") process_executor = ProcessExecutor(adhesive.process, wait_tasks=False) data = process_executor.execute() assert_equal_execution( { "Test Chrome": 1, "Test Firefox": 1, "Build Germanium Image": 2, }, data.executions, ) self.assertFalse(process_executor.events)
def test_exclusive_gateway_non_wait(self): """ Load a process with a gateway and test it.. """ adhesive.process.process = read_bpmn_file( "test/adhesive/xml/gateway-complex.bpmn") process_executor = ProcessExecutor(adhesive.process, wait_tasks=False) data = process_executor.execute() assert_equal_execution( { "Test Firefox": 1, "Test Chrome": 1, "Test Browser chrome on linux": 2, "Test Browser firefox on linux": 2, }, data.executions, ) self.assertFalse(process_executor.events)
def test_inclusive_gateway(self): """ Load a process with a gateway and test it.. """ adhesive.process.process = read_bpmn_file( "test/adhesive/xml/gateway-inclusive.bpmn") process_executor = ProcessExecutor(adhesive.process) data = process_executor.execute() assert_equal_execution( { "Test Chrome": 1, "Test Firefox": 1, "Build Germanium Image": 1, "Cleanup Broken Tasks": 1, }, data.executions, ) self.assertFalse(process_executor.events)
def test_simple_execution_non_wait(self): """ Load a simple process and execute it. """ adhesive.process.process = read_bpmn_file( "test/adhesive/xml/adhesive.bpmn") process_executor = ProcessExecutor(adhesive.process, wait_tasks=False) data = process_executor.execute() assert_equal_execution( { "Ensure Docker Tooling": 1, "Build Germanium Image": 1, "Test Chrome": 1, "Test Firefox": 1, }, data.executions, ) self.assertFalse(process_executor.events)
def test_error_interrupting(self): """ Load a process with a gateway and test it.. """ adhesive.process.process = read_bpmn_file( "test/adhesive/xml/error-event-interrupting.bpmn" ) process_executor = ProcessExecutor(adhesive.process) data = process_executor.execute() print(data._error) assert_equal_execution( { "Cleanup Broken Tasks": 1, }, data.executions, ) self.assertFalse(process_executor.events)
def test_sub_process_execution(self): """ Load a process that contains a sub process and execute it. """ adhesive.process.process = read_bpmn_file( "test/adhesive/xml/adhesive_subprocess.bpmn") process_executor = ProcessExecutor(adhesive.process) data = process_executor.execute() assert_equal_execution( { "Ensure Docker Tooling": 1, "Build Germanium Image": 1, "Prepare Firefox": 1, "Test Firefox": 1, "Test Chrome": 1, }, data.executions, ) self.assertFalse(process_executor.events)
def test_lane_non_wait(self): """ Load a process with a gateway and test it.. """ adhesive.process.process = read_bpmn_file( "test/adhesive/xml/lane.bpmn") process_executor = ProcessExecutor(adhesive.process, wait_tasks=False) data = process_executor.execute() assert_equal_execution( { "Prepare Firefox": 1, "Test Chrome": 1, "Test Firefox": 2, "Ensure Docker Tooling": 1, "Build Germanium Image": 4, }, data.executions, ) self.assertFalse(process_executor.events)
def test_parallel_sub_processes_tasks_non_wait(self): """ Load a bunch of tasks in parallel. :return: """ ProcessExecutor.pool = pebble.pool.ProcessPool(max_workers=6) adhesive.process.process = read_bpmn_file( "test/adhesive/xml/parallel5-sub-processes.bpmn") start_time = time.time() * 1000.0 ProcessExecutor(adhesive.process, wait_tasks=False).execute() end_time = time.time() * 1000.0 # the whole thing should be faster than 2 secs total_time = end_time - start_time self.assertTrue( total_time < 2000, f"Total time ({total_time}) should be less than 2000ms.") self.assertTrue( total_time >= 1000, f"Total time ({total_time}) should be more than 1000ms.")
def test_reading_unsupported_elements_fails(self) -> None: with self.assertRaises(Exception): read_bpmn_file("test/adhesive/xml/unsupported-call-activity.bpmn")