Ejemplo n.º 1
0
    def test_PARALLEL_SPLIT01(self):
        we = GenericWorkflowEngine()
        doc = self.getDoc()

        we.setWorkflow([
            i('start'),
            cf.PARALLEL_SPLIT(printer('p1'), printer('p2'), printer('p3'),
                              printer('p4'), printer('p5')),
            lambda o, e: time.sleep(.1),
            a('end')
        ])
        we.process(doc)
        r = [' '.join(doc[x]) for x in range(len(doc))]

        assert doc[0][0] == 'start'
        assert doc[0][1] == 'one'
        assert doc[1][0] == 'start'
        assert doc[1][1] == 'two'

        # end must have been inserted while printers were running
        # mixed together with them
        all_pos = set()
        for x in range(len(doc)):
            pos = doc[x].index('end')
            assert pos > 2
            assert pos < len(doc[x])
            all_pos.add(pos)
Ejemplo n.º 2
0
    def test_PARALLEL_SPLIT02(self):
        """TODO: this test is failing, but that is because sometimes it does
        not take into accounts threads being executed in random mannger"""

        we = GenericWorkflowEngine()
        doc = self.getDoc()[0:1]

        we.setWorkflow([
            i('start'),
            cf.PARALLEL_SPLIT(
                [
                    cf.PARALLEL_SPLIT(
                        printer('p0'),
                        printer('p0a'),
                        cf.PARALLEL_SPLIT(printer('p0b'), printer('p0c')),
                    ),
                    printer('xx')
                ], [a('AAA'), printer('p2b')], printer('p3'),
                [a('p4a'), printer('p4b'),
                 printer('p4c')], [
                     printer('p5'),
                     cf.PARALLEL_SPLIT(
                         printer('p6'),
                         printer('p7'),
                         [printer('p8a'), printer('p8b')],
                     )
                 ]),
            a('end')
        ])
        we.process(doc)

        # give threads time to finish
        time.sleep(2)

        assert doc[0][0] == 'start'
        assert doc[0][1] == 'one'

        # at least the fist object should have them all
        # print doc[0]
        for x in [
                'p0', 'p0a', 'p0b', 'p0c', 'xx', 'AAA', 'p2b', 'p3', 'p4a',
                'p4b', 'p4c', 'p5', 'p6', 'p8a', 'p8b'
        ]:
            doc[0].index(x)  # will fail if not present
Ejemplo n.º 3
0
    def test_PARALLEL_SPLIT03(self):
        we = GenericWorkflowEngine()
        doc = self.getDoc()

        we.setWorkflow([
            i('start'),
            cf.PARALLEL_SPLIT([
                cf.IF(lambda obj, eng: 'jump-verified' in obj, a('error')),
                cf.PARALLEL_SPLIT([
                    cf.IF(lambda obj, eng: 'nasty-jump' in obj, [
                        a('jump-ok'), lambda obj, eng:
                        ('nasty-jump' in obj and obj.append('jump-verified'))
                    ]),
                    cf.PARALLEL_SPLIT(
                        a('ok-1'), a('ok-2'),
                        cf.IF(
                            lambda obj, eng: 'ok-3' not in obj,
                            lambda obj, eng:
                            (obj.append('ok-3') and eng.breakFromThisLoop())),
                        a('ok-4')),
                    a('xx'), lambda obj, eng:
                    ('jump-verified' in obj and eng.breakFromThisLoop()),
                    a('nasty-jump'),
                    cf.TASK_JUMP_IF(
                        lambda obj, eng: 'jump-verified' not in obj, -100)
                ]),
            ], [a('AAA'), a('p2b')]),
            a('end')
        ])
        we.process(doc)
        # give threads time to finish
        time.sleep(.5)

        d = doc[0]

        # at least the fist object should have them all
        # print doc[0]
        for x in ['nasty-jump', 'jump-verified', 'ok-3']:
            d.index(x)  # will fail if not present

        assert d.count('ok-1') > 1