GitLab will be upgraded on June 23rd evening. During the upgrade the service will be unavailable, sorry for the inconvenience.

Commit eca97961 authored by Olof Svensson's avatar Olof Svensson

BES-312: Refactoring of pypushflow tests

parent 0e9c08b4
......@@ -55,7 +55,7 @@ def trace_unhandled_exceptions(func):
try:
outData = func(*args, **kwargs)
except Exception as e:
errorMessage = '{0}'.format(e)
errorMessage = 'In trace unhandled exceptions: {0}'.format(e)
logger.exception(errorMessage)
traceBack = traceback.format_exc()
return ActorWrapperException(
......
......@@ -60,7 +60,10 @@ class Submodel(object):
self.parent = parent
self.mongoId = self.parent.mongoId
self.name = name
self.errorHandler = errorHandler
if errorHandler is None:
self.errorHandler = parent
else:
self.errorHandler = errorHandler
self.dictPort = {}
self.listOnErrorActor = []
for portName in portNames:
......@@ -86,6 +89,7 @@ class Submodel(object):
logger.debug("In triggerOnError in subModule {0}, trigger actor {1}, inData = {2}".format(self.name, onErrorActor.name, args[0]))
onErrorActor.trigger(*args, **kwargs)
if self.errorHandler is not None:
logger.error('Trigger on error on errorHandler "{0}"'.format(self.errorHandler.name))
self.errorHandler.triggerOnError(*args, **kwargs)
def addActorRef(self, actorRef):
......
#
# 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__ = "08/04/2021"
import time
def run(value=None, **kwargs):
time.sleep(1)
if value is None:
raise RuntimeError("Missing argument 'value'!")
value = value + 1
return {'value': value}
......@@ -53,7 +53,7 @@ class TestUtilsMongoDb(unittest.TestCase):
actorId = UtilsMongoDb.initActor(name=actorName, workflowId=workflowId)
self.assertIsNotNone(actorId)
def test_addDataToActor(self):
def tes_addDataToActor(self):
name = 'test_initMongo'
workflowId = UtilsMongoDb.initMongo(name=name)
self.assertIsNotNone(workflowId)
......
......@@ -21,29 +21,45 @@
__authors__ = ["O. Svensson"]
__license__ = "MIT"
__date__ = "28/05/2019"
__date__ = "07/04/2021"
import os
import logging
import unittest
from pypushflow.test.TestWorkflow import Workflow1
from pypushflow.test.TestWorkflow import Workflow2
from pypushflow.test.TestWorkflow import Workflow3
from pypushflow.test.TestWorkflow import Workflow5
from pypushflow.Workflow import Workflow
from pypushflow.StopActor import StopActor
from pypushflow.StartActor import StartActor
from pypushflow.PythonActor import PythonActor
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger('testWorkflow')
class TestWorkflows(unittest.TestCase):
class Workflow1(Workflow):
"""
Workflow containing one start actor,
one python actor and one stop actor.
"""
def __init__(self, name):
Workflow.__init__(self, name)
self.startActor = StartActor(parent=self)
self.pythonActor = PythonActor(
parent=self,
script='pypushflow.test.pythonActorTest.py',
name='Python Actor Test'
)
self.stopActor = StopActor(parent=self)
self.startActor.connect(self.pythonActor)
self.pythonActor.connect(self.stopActor)
def run(self, inData):
self.startActor.trigger(inData)
self.stopActor.join(timeout=15)
return self.stopActor.outData
def setUp(self):
# Test mongodb server
# os.environ['PYPUSHFLOW_MONGOURL'] = 'mongodb://pybes:pybes@linsvensson.esrf.fr:27017/pybes'
# os.environ['PYPUSHFLOW_INITIATOR'] = 'TestWorkflows'
pass
class TestWorkflow1(unittest.TestCase):
def test_Workflow1(self):
testWorkflow1 = Workflow1('Test workflow 1')
......@@ -51,30 +67,3 @@ class TestWorkflows(unittest.TestCase):
outData = testWorkflow1.run(inData)
self.assertIsNotNone(outData)
self.assertEqual(outData['reply'], 'Hello Jerry!')
def test_Workflow2(self):
testWorkflow2 = Workflow2('Test workflow 2')
inData = {'name': 'Tom'}
outData = testWorkflow2.run(inData)
self.assertIsNotNone(outData)
self.assertTrue('WorkflowException' in outData)
def test_Workflow3(self):
testWorkflow3 = Workflow3('Test workflow 3')
inData = {'name': 'Cat'}
outData = testWorkflow3.run(inData)
self.assertIsNotNone(outData)
self.assertEqual(outData['reply'], 'Hello Cat!')
def test_Workflow4(self):
testWorkflow4 = Workflow2('Test workflow 4')
inData = {'name': 'Dog'}
outData = testWorkflow4.run(inData)
self.assertIsNotNone(outData)
self.assertTrue('WorkflowException' in outData)
def test_Workflow5(self):
testWorkflow5 = Workflow5('Test workflow 5')
inData = {'name': 'Dog'}
outData = testWorkflow5.run(inData)
self.assertIsNone(outData)
#
# 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__ = "07/04/2021"
import logging
import unittest
from pypushflow.Workflow import Workflow
from pypushflow.Submodel import Submodel
from pypushflow.StopActor import StopActor
from pypushflow.StartActor import StartActor
from pypushflow.PythonActor import PythonActor
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger('testWorkflow')
class Workflow2(Workflow):
"""
Workflow with error handling, containing one start actor,
one python actor and one stop actor.
The python actor throws an exception.
"""
def __init__(self, name):
Workflow.__init__(self, name)
self.startActor = StartActor(parent=self)
self.pythonActor = PythonActor(
parent=self,
script='pypushflow.test.pythonErrorHandlerTest.py',
name='Python Error Handler Test',
errorHandler=self
)
self.stopActor = StopActor(parent=self)
self.startActor.connect(self.pythonActor)
self.pythonActor.connect(self.stopActor)
self.connectOnError(self.stopActor)
def run(self, inData):
self.startActor.trigger(inData)
self.stopActor.join(timeout=5)
return self.stopActor.outData
class TestWorkflow2(unittest.TestCase):
def test_Workflow2(self):
testWorkflow2 = Workflow2('Test workflow 2')
inData = {'name': 'Tom'}
outData = testWorkflow2.run(inData)
self.assertIsNotNone(outData)
self.assertTrue('WorkflowException' in outData)
......@@ -21,7 +21,10 @@
__authors__ = ["O. Svensson"]
__license__ = "MIT"
__date__ = "28/05/2019"
__date__ = "07/04/2021"
import logging
import unittest
from pypushflow.Workflow import Workflow
from pypushflow.Submodel import Submodel
......@@ -29,58 +32,8 @@ from pypushflow.StopActor import StopActor
from pypushflow.StartActor import StartActor
from pypushflow.PythonActor import PythonActor
class Workflow1(Workflow):
"""
Workflow containing one start actor,
one python actor and one stop actor.
"""
def __init__(self, name):
Workflow.__init__(self, name)
self.startActor = StartActor(parent=self)
self.pythonActor = PythonActor(
parent=self,
script='pypushflow.test.pythonActorTest.py',
name='Python Actor Test'
)
self.stopActor = StopActor(parent=self)
self.startActor.connect(self.pythonActor)
self.pythonActor.connect(self.stopActor)
def run(self, inData):
self.startActor.trigger(inData)
self.stopActor.join(timeout=15)
return self.stopActor.outData
class Workflow2(Workflow):
"""
Workflow with error handling, containing one start actor,
one python actor and one stop actor.
The python actor throws an exception.
"""
def __init__(self, name):
Workflow.__init__(self, name)
self.startActor = StartActor(parent=self)
self.pythonActor = PythonActor(
parent=self,
script='pypushflow.test.pythonErrorHandlerTest.py',
name='Python Error Handler Test',
errorHandler=self
)
self.stopActor = StopActor(parent=self)
self.startActor.connect(self.pythonActor)
self.pythonActor.connect(self.stopActor)
self.connectOnError(self.stopActor)
def run(self, inData):
self.startActor.trigger(inData)
self.stopActor.join(timeout=5)
return self.stopActor.outData
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger('testWorkflow')
class Submodel1(Submodel):
"""
......@@ -118,75 +71,11 @@ class Workflow3(Workflow):
return self.stopActor.outData
class Submodel2(Submodel):
"""
Submodel containing one python actor which throws an exception.
"""
def __init__(self, parent, name):
Submodel.__init__(self, parent, name=name)
self.pythonActor = PythonActor(
parent=self,
script='pypushflow.test.pythonErrorHandlerTest.py',
name='Python Error Handler Test',
errorHandler=self
)
self.getPort('In').connect(self.pythonActor)
self.pythonActor.connect(self.getPort('Out'))
class Submodel3(Submodel):
"""
Submodel containing one python actor which has a long execution time
"""
def __init__(self, parent, name):
Submodel.__init__(self, parent, name=name)
self.pythonActor = PythonActor(
parent=self,
script='pypushflow.test.pythonLongExecutionTest.py',
name='Python Long Execution Test',
errorHandler=self
)
self.getPort('In').connect(self.pythonActor)
self.pythonActor.connect(self.getPort('Out'))
class Workflow4(Workflow):
"""
Workflow containing one start actor,
one submodel which throws an exception and one stop actor.
"""
def __init__(self, name):
Workflow.__init__(self, name)
self.startActor = StartActor()
self.submodel2 = Submodel2('Submodel 2')
self.stopActor = StopActor()
self.startActor.connect(self.submodel2.getPort('In'))
self.submodel2.getPort('Out').connect(self.stopActor)
def run(self, inData):
self.startActor.trigger(inData)
self.stopActor.join(timeout=5)
return self.stopActor.outData
class Workflow5(Workflow):
"""
Workflow containing one start actor,
one submodel which has a long execution and one stop actor with short timeout.
"""
def __init__(self, name):
Workflow.__init__(self, name)
self.startActor = StartActor(self)
self.submodel3 = Submodel3(self, name='Submodel 3')
self.stopActor = StopActor(self)
self.startActor.connect(self.submodel3.getPort('In'))
self.submodel3.getPort('Out').connect(self.stopActor)
class TestWorkflow3(unittest.TestCase):
def run(self, inData):
self.startActor.trigger(inData)
self.stopActor.join(timeout=5)
return self.stopActor.outData
def test_workflow3(self):
testWorkflow3 = Workflow3('Test workflow 3')
inData = {'name': 'Cat'}
outData = testWorkflow3.run(inData)
self.assertIsNotNone(outData)
self.assertEqual(outData['reply'], 'Hello Cat!')
#
# 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__ = "07/04/2021"
import logging
import unittest
from pypushflow.Workflow import Workflow
from pypushflow.Submodel import Submodel
from pypushflow.StopActor import StopActor
from pypushflow.StartActor import StartActor
from pypushflow.PythonActor import PythonActor
from pypushflow.ErrorHandler import ErrorHandler
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger('testWorkflow')
class Submodel4(Submodel):
"""
Submodel containing one python actor which throws an exception.
"""
def __init__(self, parent, name):
Submodel.__init__(self, parent, name=name)
self.pythonActor = PythonActor(
parent=self,
script='pypushflow.test.pythonErrorHandlerTest.py',
name='Python Error Handler Test',
errorHandler=self
)
self.getPort('In').connect(self.pythonActor)
self.pythonActor.connect(self.getPort('Out'))
class Workflow4(Workflow):
"""
Workflow containing one start actor,
one submodel which throws an exception and one stop actor.
"""
def __init__(self, name):
Workflow.__init__(self, name)
self.startActor = StartActor()
self.submodel4 = Submodel4(parent=self, name='Submodel 4')
self.stopActor = StopActor()
self.startActor.connect(self.submodel4.getPort('In'))
self.submodel4.getPort('Out').connect(self.stopActor)
self.connectOnError(self.stopActor)
def run(self, inData):
self.startActor.trigger(inData)
self.stopActor.join(timeout=5)
return self.stopActor.outData
class TestWorkflow4(unittest.TestCase):
def test_workflow4(self):
workflow4 = Workflow4('Test workflow 4')
inData = {'name': 'Dog'}
outData = workflow4.run(inData)
self.assertIsNotNone(outData)
self.assertTrue('WorkflowException' in outData)
\ No newline at end of file
#
# 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__ = "07/04/2021"
import logging
import unittest
from pypushflow.Workflow import Workflow
from pypushflow.Submodel import Submodel
from pypushflow.StopActor import StopActor
from pypushflow.StartActor import StartActor
from pypushflow.PythonActor import PythonActor
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger('testWorkflow')
class Submodel5(Submodel):
"""
Submodel containing one python actor which has a long execution time
"""
def __init__(self, parent, name):
Submodel.__init__(self, parent, name=name)
self.pythonActor = PythonActor(
parent=self,
script='pypushflow.test.pythonLongExecutionTest.py',
name='Python Long Execution Test',
errorHandler=self
)
self.getPort('In').connect(self.pythonActor)
self.pythonActor.connect(self.getPort('Out'))
class Workflow5(Workflow):
"""
Workflow containing one start actor,
one submodel which has a long execution and one stop actor with short timeout.
"""
def __init__(self, name):
Workflow.__init__(self, name)
self.startActor = StartActor(self)
self.submodel5 = Submodel5(self, name='Submodel 5')
self.stopActor = StopActor(self)
self.startActor.connect(self.submodel5.getPort('In'))
self.submodel5.getPort('Out').connect(self.stopActor)
def run(self, inData):
self.startActor.trigger(inData)
self.stopActor.join(timeout=5)
return self.stopActor.outData
class TestWorkflow5(unittest.TestCase):
def test_Workflow5(self):
testWorkflow5 = Workflow5('Test workflow 5')
inData = {'name': 'Dog'}
outData = testWorkflow5.run(inData)
self.assertIsNone(outData)
#
# 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__ = "07/04/2021"
import logging
import unittest
from pypushflow.Workflow import Workflow
from pypushflow.Submodel import Submodel
from pypushflow.StopActor import StopActor
from pypushflow.StartActor import StartActor
from pypushflow.PythonActor import PythonActor
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger('testWorkflow')
class Submodel6(Submodel):
"""
Submodel containing one python actor which has a long execution time
"""
def __init__(self, parent, name):
Submodel.__init__(self, parent, name=name)
self.pythonActorAdd = PythonActor(
parent=self,
script='pypushflow.test.pythonActorAdd.py',
name='Python Submodel Actor Add',
errorHandler=self
)
self.getPort('In').connect(self.pythonActorAdd)
self.pythonActorAdd.connect(self.getPort('Out'))
class Workflow6(Workflow):
"""
Workflow containing one start actor,
one submodel which has a long execution and one stop actor with short timeout.
"""
def __init__(self, name):
Workflow.__init__(self, name)
self.startActor = StartActor(self)
self.pythonActorAdd1 = PythonActor(
parent=self,
script='pypushflow.test.pythonActorAdd.py',
name='Python Add Actor 1',
)
self.pythonActorAdd2 = PythonActor(
parent=self,
script='pypushflow.test.pythonActorAdd.py',
name='Python Add Actor 2',