Commit 7ad32046 authored by Julien Muchembled's avatar Julien Muchembled

Fix 2 bugs in unit tests

- delay patch to Activity Tool on Zope 2.12
- fix possible failure when starting processing nodes

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@35393 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 702276a6
...@@ -155,7 +155,8 @@ except ImportError: ...@@ -155,7 +155,8 @@ except ImportError:
pass pass
from Products.ERP5Type.tests.ProcessingNodeTestCase import \ from Products.ERP5Type.tests.ProcessingNodeTestCase import \
ProcessingNodeTestCase ProcessingNodeTestCase, patchActivityTool
onsetup(patchActivityTool)()
ZopeTestCase.installProduct('TimerService', quiet=install_product_quiet) ZopeTestCase.installProduct('TimerService', quiet=install_product_quiet)
......
# This module must be imported before CMFActivity product is installed.
import base64, errno, select, socket, time import base64, errno, select, socket, time
from threading import Thread from threading import Thread
import Lifetime import Lifetime
import transaction import transaction
from BTrees.OIBTree import OIBTree from BTrees.OIBTree import OIBTree
from Testing import ZopeTestCase from Testing import ZopeTestCase
from Products.CMFActivity import ActivityTool as _ActivityTool
from Products.CMFActivity.Activity.Queue import VALIDATION_ERROR_DELAY from Products.CMFActivity.Activity.Queue import VALIDATION_ERROR_DELAY
from Products.ERP5Type.tests import backportUnittest from Products.ERP5Type.tests import backportUnittest
from Products.ERP5Type.tests.utils import createZServer from Products.ERP5Type.tests.utils import createZServer
class ActivityTool(_ActivityTool.ActivityTool): def patchActivityTool():
"""Class redefining CMFActivity.ActivityTool.ActivityTool for unit tests """Redefine several methods of ActivityTool for unit tests
""" """
from Products.CMFActivity.ActivityTool import ActivityTool
def patch(function):
name = function.__name__
setattr(ActivityTool, '_orig_' + name, getattr(ActivityTool, name))
setattr(ActivityTool, name, function)
# When a ZServer can't be started, the node name ends with ':' (no port). # When a ZServer can't be started, the node name ends with ':' (no port).
@patch
def _isValidNodeName(self, node_name): def _isValidNodeName(self, node_name):
return True return True
...@@ -26,28 +29,31 @@ class ActivityTool(_ActivityTool.ActivityTool): ...@@ -26,28 +29,31 @@ class ActivityTool(_ActivityTool.ActivityTool):
# Properties at the root are: # Properties at the root are:
# - 'test_processing_nodes' to list processing nodes # - 'test_processing_nodes' to list processing nodes
# - 'test_distributing_node' to select the distributing node # - 'test_distributing_node' to select the distributing node
@patch
def getNodeDict(self): def getNodeDict(self):
app = self.getPhysicalRoot() app = self.getPhysicalRoot()
if getattr(app, 'test_processing_nodes', None) is None: if getattr(app, 'test_processing_nodes', None) is None:
app.test_processing_nodes = OIBTree() app.test_processing_nodes = OIBTree()
return app.test_processing_nodes return app.test_processing_nodes
@patch
def getDistributingNode(self): def getDistributingNode(self):
return self.getPhysicalRoot().test_distributing_node return self.getPhysicalRoot().test_distributing_node
@patch
def manage_setDistributingNode(self, distributingNode, REQUEST=None): def manage_setDistributingNode(self, distributingNode, REQUEST=None):
# A property to catch setattr on 'distributingNode' doesn't work # A property to catch setattr on 'distributingNode' doesn't work
# because self would lose all acquisition wrappers. # because self would lose all acquisition wrappers.
previous_node = self.distributingNode previous_node = self.distributingNode
try: try:
super(ActivityTool, self).manage_setDistributingNode(distributingNode, self._orig_manage_setDistributingNode(distributingNode, REQUEST=REQUEST)
REQUEST=REQUEST)
self.getPhysicalRoot().test_distributing_node = self.distributingNode self.getPhysicalRoot().test_distributing_node = self.distributingNode
finally: finally:
self.distributingNode = previous_node self.distributingNode = previous_node
# When there is more than 1 node, prevent the distributing node from # When there is more than 1 node, prevent the distributing node from
# processing activities. # processing activities.
@patch
def tic(self, processing_node=1, force=0): def tic(self, processing_node=1, force=0):
processing_node_list = self.getProcessingNodeList() processing_node_list = self.getProcessingNodeList()
if len(processing_node_list) > 1 and \ if len(processing_node_list) > 1 and \
...@@ -56,9 +62,7 @@ class ActivityTool(_ActivityTool.ActivityTool): ...@@ -56,9 +62,7 @@ class ActivityTool(_ActivityTool.ActivityTool):
time.sleep(0.3) time.sleep(0.3)
transaction.commit() transaction.commit()
else: else:
super(ActivityTool, self).tic(processing_node, force) self._orig_tic(processing_node, force)
_ActivityTool.ActivityTool = ActivityTool
class ProcessingNodeTestCase(backportUnittest.TestCase, ZopeTestCase.TestCase): class ProcessingNodeTestCase(backportUnittest.TestCase, ZopeTestCase.TestCase):
...@@ -98,6 +102,7 @@ class ProcessingNodeTestCase(backportUnittest.TestCase, ZopeTestCase.TestCase): ...@@ -98,6 +102,7 @@ class ProcessingNodeTestCase(backportUnittest.TestCase, ZopeTestCase.TestCase):
try: try:
activity_tool = self.portal.portal_activities activity_tool = self.portal.portal_activities
except AttributeError: except AttributeError:
from Products.CMFActivity.ActivityTool import ActivityTool
activity_tool = ActivityTool().__of__(self.app) activity_tool = ActivityTool().__of__(self.app)
currentNode = activity_tool.getCurrentNode() currentNode = activity_tool.getCurrentNode()
if distributing: if distributing:
...@@ -166,7 +171,7 @@ class ProcessingNodeTestCase(backportUnittest.TestCase, ZopeTestCase.TestCase): ...@@ -166,7 +171,7 @@ class ProcessingNodeTestCase(backportUnittest.TestCase, ZopeTestCase.TestCase):
transaction.begin() transaction.begin()
try: try:
portal = self.app[self.app.test_portal_name] portal = self.app[self.app.test_portal_name]
except AttributeError: except (AttributeError, KeyError):
continue continue
portal.portal_activities.process_timer(None, None) portal.portal_activities.process_timer(None, None)
except KeyboardInterrupt: except KeyboardInterrupt:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment