Esempio n. 1
0
    def test_workflow_spec_cache_update_via_workbook_service(self):
        wb_text = """
        version: '2.0'

        name: wb

        workflows:
          wf:
            tasks:
              task1:
                action: std.echo output="Echo"
        """

        wb_service.create_workbook_v2(wb_text)

        self.assertEqual(0, spec_parser.get_wf_execution_spec_cache_size())
        self.assertEqual(0, spec_parser.get_wf_definition_spec_cache_size())

        wf = db_api.get_workflow_definition('wb.wf')

        wf_spec = spec_parser.get_workflow_spec_by_definition_id(
            wf.id, wf.updated_at)

        self.assertEqual(1, len(wf_spec.get_tasks()))
        self.assertEqual(0, spec_parser.get_wf_execution_spec_cache_size())
        self.assertEqual(1, spec_parser.get_wf_definition_spec_cache_size())

        # Now update workflow definition and check that cache is updated too.

        wb_text = """
        version: '2.0'

        name: wb

        workflows:
          wf:
            tasks:
              task1:
                action: std.echo output="1"

              task2:
                action: std.echo output="2"
        """

        wb_service.update_workbook_v2(wb_text)

        self.assertEqual(0, spec_parser.get_wf_execution_spec_cache_size())
        self.assertEqual(1, spec_parser.get_wf_definition_spec_cache_size())

        wf = db_api.get_workflow_definition(wf.id)

        wf_spec = spec_parser.get_workflow_spec_by_definition_id(
            wf.id, wf.updated_at)

        self.assertEqual(2, len(wf_spec.get_tasks()))
        self.assertEqual(0, spec_parser.get_wf_execution_spec_cache_size())
        self.assertEqual(2, spec_parser.get_wf_definition_spec_cache_size())
Esempio n. 2
0
    def test_cache_workflow_spec_no_duplicates(self):
        wfs_text = """
        version: '2.0'

        wf:
          tasks:
            task1:
              action: std.noop
              on-success:
                - task2
                - task3

            task2:
              workflow: sub_wf my_param="val1"

            task3:
              workflow: sub_wf my_param="val2"

        sub_wf:
          input:
            - my_param

          tasks:
            task1:
              action: std.echo output="Param value is <% $.my_param %>"
        """

        wfs = wf_service.create_workflows(wfs_text)

        self.assertEqual(2, len(wfs))

        self.assertEqual(0, spec_parser.get_wf_execution_spec_cache_size())
        self.assertEqual(0, spec_parser.get_wf_definition_spec_cache_size())

        wf_ex = self.engine.start_workflow('wf')

        self.await_workflow_success(wf_ex.id)

        # We expect to have a cache entry for every workflow execution
        # but two of them should refer to the same object.
        self.assertEqual(3, spec_parser.get_wf_execution_spec_cache_size())
        self.assertEqual(2, spec_parser.get_wf_definition_spec_cache_size())

        sub_wf_execs = db_api.get_workflow_executions(name='sub_wf')

        self.assertEqual(2, len(sub_wf_execs))

        spec1 = spec_parser.get_workflow_spec_by_execution_id(
            sub_wf_execs[0].id
        )
        spec2 = spec_parser.get_workflow_spec_by_execution_id(
            sub_wf_execs[1].id
        )

        self.assertIs(spec1, spec2)
Esempio n. 3
0
    def test_cache_workflow_spec_no_duplicates(self):
        wfs_text = """
        version: '2.0'

        wf:
          tasks:
            task1:
              action: std.noop
              on-success:
                - task2
                - task3

            task2:
              workflow: sub_wf my_param="val1"

            task3:
              workflow: sub_wf my_param="val2"

        sub_wf:
          input:
            - my_param

          tasks:
            task1:
              action: std.echo output="Param value is <% $.my_param %>"
        """

        wfs = wf_service.create_workflows(wfs_text)

        self.assertEqual(2, len(wfs))

        self.assertEqual(0, spec_parser.get_wf_execution_spec_cache_size())
        self.assertEqual(0, spec_parser.get_wf_definition_spec_cache_size())

        wf_ex = self.engine.start_workflow('wf')

        self.await_workflow_success(wf_ex.id)

        # We expect to have a cache entry for every workflow execution
        # but two of them should refer to the same object.
        self.assertEqual(3, spec_parser.get_wf_execution_spec_cache_size())
        self.assertEqual(2, spec_parser.get_wf_definition_spec_cache_size())

        sub_wf_execs = db_api.get_workflow_executions(name='sub_wf')

        self.assertEqual(2, len(sub_wf_execs))

        spec1 = spec_parser.get_workflow_spec_by_execution_id(
            sub_wf_execs[0].id)
        spec2 = spec_parser.get_workflow_spec_by_execution_id(
            sub_wf_execs[1].id)

        self.assertIs(spec1, spec2)
Esempio n. 4
0
    def test_workflow_spec_cache_update_via_workflow_service(self):
        wf_text = """
        version: '2.0'

        wf:
          tasks:
            task1:
              action: std.echo output="Echo"
        """

        wfs = wf_service.create_workflows(wf_text)

        self.assertEqual(0, spec_parser.get_wf_execution_spec_cache_size())
        self.assertEqual(0, spec_parser.get_wf_definition_spec_cache_size())

        wf_spec = spec_parser.get_workflow_spec_by_definition_id(
            wfs[0].id,
            wfs[0].updated_at
        )

        self.assertEqual(1, len(wf_spec.get_tasks()))
        self.assertEqual(0, spec_parser.get_wf_execution_spec_cache_size())
        self.assertEqual(1, spec_parser.get_wf_definition_spec_cache_size())

        # Now update workflow definition and check that cache is updated too.

        wf_text = """
        version: '2.0'

        wf:
          tasks:
            task1:
              action: std.echo output="1"

            task2:
              action: std.echo output="2"
        """

        wfs = wf_service.update_workflows(wf_text)

        self.assertEqual(1, spec_parser.get_wf_definition_spec_cache_size())

        wf_spec = spec_parser.get_workflow_spec_by_definition_id(
            wfs[0].id,
            wfs[0].updated_at
        )

        self.assertEqual(2, len(wf_spec.get_tasks()))
        self.assertEqual(2, spec_parser.get_wf_definition_spec_cache_size())
        self.assertEqual(0, spec_parser.get_wf_execution_spec_cache_size())
Esempio n. 5
0
    def test_workflow_spec_cache_update_via_workflow_service(self):
        wf_text = """
        version: '2.0'

        wf:
          tasks:
            task1:
              action: std.echo output="Echo"
        """

        wfs = wf_service.create_workflows(wf_text)

        self.assertEqual(0, spec_parser.get_wf_execution_spec_cache_size())
        self.assertEqual(0, spec_parser.get_wf_definition_spec_cache_size())

        wf_spec = spec_parser.get_workflow_spec_by_definition_id(
            wfs[0].id, wfs[0].updated_at)

        self.assertEqual(1, len(wf_spec.get_tasks()))
        self.assertEqual(0, spec_parser.get_wf_execution_spec_cache_size())
        self.assertEqual(1, spec_parser.get_wf_definition_spec_cache_size())

        # Now update workflow definition and check that cache is updated too.

        wf_text = """
        version: '2.0'

        wf:
          tasks:
            task1:
              action: std.echo output="1"

            task2:
              action: std.echo output="2"
        """

        wfs = wf_service.update_workflows(wf_text)

        self.assertEqual(1, spec_parser.get_wf_definition_spec_cache_size())

        wf_spec = spec_parser.get_workflow_spec_by_definition_id(
            wfs[0].id, wfs[0].updated_at)

        self.assertEqual(2, len(wf_spec.get_tasks()))
        self.assertEqual(2, spec_parser.get_wf_definition_spec_cache_size())
        self.assertEqual(0, spec_parser.get_wf_execution_spec_cache_size())
Esempio n. 6
0
    def test_workflow_spec_caching(self):
        wf_text = """
        version: '2.0'

        wf:
          tasks:
            task1:
              action: std.echo output="Echo"
        """

        wfs = wf_service.create_workflows(wf_text)

        self.assertEqual(0, spec_parser.get_wf_execution_spec_cache_size())
        self.assertEqual(0, spec_parser.get_wf_definition_spec_cache_size())

        wf_spec = spec_parser.get_workflow_spec_by_definition_id(
            wfs[0].id, wfs[0].updated_at)

        self.assertIsNotNone(wf_spec)
        self.assertEqual(0, spec_parser.get_wf_execution_spec_cache_size())
        self.assertEqual(1, spec_parser.get_wf_definition_spec_cache_size())
Esempio n. 7
0
    def test_workflow_spec_caching(self):
        wf_text = """
        version: '2.0'

        wf:
          tasks:
            task1:
              action: std.echo output="Echo"
        """

        wfs = wf_service.create_workflows(wf_text)

        self.assertEqual(0, spec_parser.get_wf_execution_spec_cache_size())
        self.assertEqual(0, spec_parser.get_wf_definition_spec_cache_size())

        wf_spec = spec_parser.get_workflow_spec_by_definition_id(
            wfs[0].id,
            wfs[0].updated_at
        )

        self.assertIsNotNone(wf_spec)
        self.assertEqual(0, spec_parser.get_wf_execution_spec_cache_size())
        self.assertEqual(1, spec_parser.get_wf_definition_spec_cache_size())
Esempio n. 8
0
    def test_cache_workflow_spec_by_execution_id(self):
        wf_text = """
        version: '2.0'

        wf:
          tasks:
            task1:
              action: std.echo output="Echo"
        """

        wfs = wf_service.create_workflows(wf_text)

        self.assertEqual(0, spec_parser.get_wf_execution_spec_cache_size())
        self.assertEqual(0, spec_parser.get_wf_definition_spec_cache_size())

        wf_def = wfs[0]

        wf_spec = spec_parser.get_workflow_spec_by_definition_id(
            wf_def.id, wf_def.updated_at)

        self.assertEqual(1, len(wf_spec.get_tasks()))
        self.assertEqual(0, spec_parser.get_wf_execution_spec_cache_size())
        self.assertEqual(1, spec_parser.get_wf_definition_spec_cache_size())

        with db_api.transaction():
            wf_ex = db_api.create_workflow_execution({
                'id': '1-2-3-4',
                'name': 'wf',
                'workflow_id': wf_def.id,
                'spec': wf_spec.to_dict(),
                'state': states.RUNNING
            })

            # Check that we can get a valid spec by execution id.
            wf_spec_by_exec_id = spec_parser.get_workflow_spec_by_execution_id(
                wf_ex.id)

        self.assertEqual(1, len(wf_spec_by_exec_id.get_tasks()))

        # Now update workflow definition and check that cache is updated too.

        wf_text = """
        version: '2.0'

        wf:
          tasks:
            task1:
              action: std.echo output="1"

            task2:
              action: std.echo output="2"
        """

        wfs = wf_service.update_workflows(wf_text)

        self.assertEqual(1, spec_parser.get_wf_definition_spec_cache_size())

        wf_spec = spec_parser.get_workflow_spec_by_definition_id(
            wfs[0].id, wfs[0].updated_at)

        self.assertEqual(2, len(wf_spec.get_tasks()))
        self.assertEqual(2, spec_parser.get_wf_definition_spec_cache_size())
        self.assertEqual(1, spec_parser.get_wf_execution_spec_cache_size())

        # Now finally update execution cache and check that we can
        # get a valid spec by execution id.
        spec_parser.cache_workflow_spec_by_execution_id(wf_ex.id, wf_spec)

        wf_spec_by_exec_id = spec_parser.get_workflow_spec_by_execution_id(
            wf_ex.id)

        self.assertEqual(2, len(wf_spec_by_exec_id.get_tasks()))
    def test_big_on_closures(self):
        # The idea of the test is to run a workflow with a big 'on-success'
        # list of tasks and big task inbound context ('task_ex.in_context)
        # and observe how it influences memory consumption and performance.
        # The test doesn't have any assertions related to memory(CPU) usage
        # because it's quite difficult to do them. Particular metrics may
        # vary from run to run and also depend on the platform.

        sub_wf_text = """
        version: '2.0'

        sub_wf:
          tasks:
            task1:
              action: std.noop
        """

        wf_text = """
        version: '2.0'

        wf:
          tasks:
            task01:
              action: std.noop
              on-success: task02

            task02:
              action: std.test_dict size=1000 key_prefix='key' val='val'
              publish:
                continue_flag: true
                data: <% task().result %>
              on-success: task0

            task0:
              workflow: sub_wf
              on-success: {{{__ON_SUCCESS_LIST__}}}

            {{{__TASK_LIST__}}}
        """

        # Generate the workflow text.
        task_cnt = 50

        on_success_list_str = ''

        for i in range(1, task_cnt + 1):
            on_success_list_str += ('\n                - task{}: '
                                    '<% $.continue_flag = true %>'.format(i))

        wf_text = wf_text.replace('{{{__ON_SUCCESS_LIST__}}}',
                                  on_success_list_str)

        task_list_str = ''

        task_template = """
            task{}:
              action: std.noop
        """

        for i in range(1, task_cnt + 1):
            task_list_str += task_template.format(i)

        wf_text = wf_text.replace('{{{__TASK_LIST__}}}', task_list_str)

        wf_service.create_workflows(sub_wf_text)
        wf_service.create_workflows(wf_text)

        # Start the workflow.
        wf_ex = self.engine.start_workflow('wf')

        self.await_workflow_success(wf_ex.id, timeout=60)

        self.assertEqual(2, spec_parser.get_wf_execution_spec_cache_size())

        with db_api.transaction():
            wf_ex = db_api.get_workflow_execution(wf_ex.id)

            task_execs = wf_ex.task_executions

        self.assertEqual(task_cnt + 3, len(task_execs))

        self._assert_single_item(task_execs, name='task0')
        self._assert_single_item(task_execs, name='task{}'.format(task_cnt))
Esempio n. 10
0
    def test_workflow_spec_cache_update_via_workbook_service(self):
        wb_text = """
        version: '2.0'

        name: wb

        workflows:
          wf:
            tasks:
              task1:
                action: std.echo output="Echo"
        """

        wb_service.create_workbook_v2(wb_text)

        self.assertEqual(0, spec_parser.get_wf_execution_spec_cache_size())
        self.assertEqual(0, spec_parser.get_wf_definition_spec_cache_size())

        wf = db_api.get_workflow_definition('wb.wf')

        wf_spec = spec_parser.get_workflow_spec_by_definition_id(
            wf.id,
            wf.updated_at
        )

        self.assertEqual(1, len(wf_spec.get_tasks()))
        self.assertEqual(0, spec_parser.get_wf_execution_spec_cache_size())
        self.assertEqual(1, spec_parser.get_wf_definition_spec_cache_size())

        # Now update workflow definition and check that cache is updated too.

        wb_text = """
        version: '2.0'

        name: wb

        workflows:
          wf:
            tasks:
              task1:
                action: std.echo output="1"

              task2:
                action: std.echo output="2"
        """

        wb_service.update_workbook_v2(wb_text)

        self.assertEqual(0, spec_parser.get_wf_execution_spec_cache_size())
        self.assertEqual(1, spec_parser.get_wf_definition_spec_cache_size())

        wf = db_api.get_workflow_definition(wf.id)

        wf_spec = spec_parser.get_workflow_spec_by_definition_id(
            wf.id,
            wf.updated_at
        )

        self.assertEqual(2, len(wf_spec.get_tasks()))
        self.assertEqual(0, spec_parser.get_wf_execution_spec_cache_size())
        self.assertEqual(2, spec_parser.get_wf_definition_spec_cache_size())
Esempio n. 11
0
    def test_cache_workflow_spec_by_execution_id(self):
        wf_text = """
        version: '2.0'

        wf:
          tasks:
            task1:
              action: std.echo output="Echo"
        """

        wfs = wf_service.create_workflows(wf_text)

        self.assertEqual(0, spec_parser.get_wf_execution_spec_cache_size())
        self.assertEqual(0, spec_parser.get_wf_definition_spec_cache_size())

        wf_def = wfs[0]

        wf_spec = spec_parser.get_workflow_spec_by_definition_id(
            wf_def.id,
            wf_def.updated_at
        )

        self.assertEqual(1, len(wf_spec.get_tasks()))
        self.assertEqual(0, spec_parser.get_wf_execution_spec_cache_size())
        self.assertEqual(1, spec_parser.get_wf_definition_spec_cache_size())

        wf_ex = db_api.create_workflow_execution({
            'id': '1-2-3-4',
            'name': 'wf',
            'workflow_id': wf_def.id,
            'spec': wf_spec.to_dict(),
            'state': states.RUNNING
        })

        # Check that we can get a valid spec by execution id.

        wf_spec_by_exec_id = spec_parser.get_workflow_spec_by_execution_id(
            wf_ex.id
        )

        self.assertEqual(1, len(wf_spec_by_exec_id.get_tasks()))

        # Now update workflow definition and check that cache is updated too.

        wf_text = """
        version: '2.0'

        wf:
          tasks:
            task1:
              action: std.echo output="1"

            task2:
              action: std.echo output="2"
        """

        wfs = wf_service.update_workflows(wf_text)

        self.assertEqual(1, spec_parser.get_wf_definition_spec_cache_size())

        wf_spec = spec_parser.get_workflow_spec_by_definition_id(
            wfs[0].id,
            wfs[0].updated_at
        )

        self.assertEqual(2, len(wf_spec.get_tasks()))
        self.assertEqual(2, spec_parser.get_wf_definition_spec_cache_size())
        self.assertEqual(1, spec_parser.get_wf_execution_spec_cache_size())

        # Now finally update execution cache and check that we can
        # get a valid spec by execution id.
        spec_parser.cache_workflow_spec_by_execution_id(wf_ex.id, wf_spec)

        wf_spec_by_exec_id = spec_parser.get_workflow_spec_by_execution_id(
            wf_ex.id
        )

        self.assertEqual(2, len(wf_spec_by_exec_id.get_tasks()))
Esempio n. 12
0
    def test_big_on_closures(self):
        # The idea of the test is to run a workflow with a big 'on-success'
        # list of tasks and big task inbound context ('task_ex.in_context)
        # and observe how it influences memory consumption and performance.
        # The test doesn't have any assertions related to memory(CPU) usage
        # because it's quite difficult to do them. Particular metrics may
        # vary from run to run and also depend on the platform.

        sub_wf_text = """
        version: '2.0'

        sub_wf:
          tasks:
            task1:
              action: std.noop
        """

        wf_text = """
        version: '2.0'

        wf:
          tasks:
            task01:
              action: std.noop
              on-success: task02

            task02:
              action: std.test_dict size=1000 key_prefix='key' val='val'
              publish:
                continue_flag: true
                data: <% task().result %>
              on-success: task0

            task0:
              workflow: sub_wf
              on-success: {{{__ON_SUCCESS_LIST__}}}

            {{{__TASK_LIST__}}}
        """

        # Generate the workflow text.
        task_cnt = 50

        on_success_list_str = ''

        for i in range(1, task_cnt + 1):
            on_success_list_str += (
                '\n                - task{}: '
                '<% $.continue_flag = true %>'.format(i)
            )

        wf_text = wf_text.replace(
            '{{{__ON_SUCCESS_LIST__}}}',
            on_success_list_str
        )

        task_list_str = ''

        task_template = """
            task{}:
              action: std.noop
        """

        for i in range(1, task_cnt + 1):
            task_list_str += task_template.format(i)

        wf_text = wf_text.replace('{{{__TASK_LIST__}}}', task_list_str)

        wf_service.create_workflows(sub_wf_text)
        wf_service.create_workflows(wf_text)

        # Start the workflow.
        wf_ex = self.engine.start_workflow('wf')

        self.await_workflow_success(wf_ex.id, timeout=60)

        self.assertEqual(2, spec_parser.get_wf_execution_spec_cache_size())

        with db_api.transaction():
            wf_ex = db_api.get_workflow_execution(wf_ex.id)

            task_execs = wf_ex.task_executions

        self.assertEqual(task_cnt + 3, len(task_execs))

        self._assert_single_item(task_execs, name='task0')
        self._assert_single_item(task_execs, name='task{}'.format(task_cnt))