test_workflow10.py 3.16 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#
# Copyright (c) European Synchrotron Radiation Facility (ESRF)
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#

__authors__ = ["O. Svensson"]
__license__ = "MIT"
__date__ = "03/05/2021"

import logging
import unittest

from pypushflow.Workflow import Workflow
from pypushflow.StopActor import StopActor
from pypushflow.StartActor import StartActor
from pypushflow.PythonActor import PythonActor
from pypushflow.RouterActor import RouterActor
Wout De Nolf's avatar
Wout De Nolf committed
34
35
from pypushflow.ThreadCounter import ThreadCounter

36
37

logging.basicConfig(level=logging.INFO)
Wout De Nolf's avatar
Wout De Nolf committed
38
logger = logging.getLogger("testWorkflow")
39
40
41
42


class Workflow10(Workflow):
    def __init__(self, name):
Wout De Nolf's avatar
Wout De Nolf committed
43
44
45
        super().__init__(name)
        ctr = ThreadCounter()
        self.startActor = StartActor(self, thread_counter=ctr)
46
        self.pythonActorAddWithoutSleep = PythonActor(
47
            parent=self,
Wout De Nolf's avatar
Wout De Nolf committed
48
49
50
            script="pypushflow.test.pythonActorAddWithoutSleep.py",
            name="Add without sleep",
            thread_counter=ctr,
51
52
53
        )
        self.pythonActorCheck = PythonActor(
            parent=self,
Wout De Nolf's avatar
Wout De Nolf committed
54
55
56
            script="pypushflow.test.pythonActorCheck.py",
            name="Check",
            thread_counter=ctr,
57
58
59
        )
        self.check = RouterActor(
            parent=self,
Wout De Nolf's avatar
Wout De Nolf committed
60
            name="Check",
61
            itemName="doContinue",
Wout De Nolf's avatar
Wout De Nolf committed
62
63
            listPort=["true", "false"],
            thread_counter=ctr,
64
        )
Wout De Nolf's avatar
Wout De Nolf committed
65
        self.stopActor = StopActor(self, thread_counter=ctr)
66
67
68
69
        self.startActor.connect(self.pythonActorAddWithoutSleep)
        self.pythonActorAddWithoutSleep.connect(self.pythonActorCheck)
        self.pythonActorCheck.connect(self.check)
        self.check.connect(self.pythonActorAddWithoutSleep, expectedValue="true")
70
71
72
73
74
75
76
77
78
        self.check.connect(self.stopActor, expectedValue="false")

    def run(self, inData):
        self.startActor.trigger(inData)
        self.stopActor.join(timeout=1200)
        return self.stopActor.outData


class TestWorkflow10(unittest.TestCase):
79
    def test_workflow10(self):
80
        limit = 10
Wout De Nolf's avatar
Wout De Nolf committed
81
82
        workflow10 = Workflow10("Test workflow {0}".format(limit))
        inData = {"value": 1, "limit": limit}
83
        outData = workflow10.run(inData)
Wout De Nolf's avatar
Wout De Nolf committed
84
        self.assertEqual(outData["value"], limit)