Commit 26390e40 authored by Jérome Perrin's avatar Jérome Perrin

ERP5TypeFunctionalTestCase: make sure activities are not subscribed

Invoking Zuite_waitForActivities when portal_activities is already
subscribed and while another thread from this process is already
executing activities causes infinite "Got a lock error, retrying...".

This situation happens when developer makes a mistake (runs the
tests without unsubscribing activities), so be nice to the developer
so that they don't have to restart Zope.
parent 9f14146f
import itertools import itertools
import time import time
from Products.CMFActivity.Activity.Queue import VALIDATION_ERROR_DELAY from Products.CMFActivity.Activity.Queue import VALIDATION_ERROR_DELAY
from Products.CMFActivity.ActivityTool import getCurrentNode
def waitForActivities(self, delay=100, count=None): def waitForActivities(self, delay=100, count=None):
""" """
...@@ -9,13 +10,17 @@ def waitForActivities(self, delay=100, count=None): ...@@ -9,13 +10,17 @@ def waitForActivities(self, delay=100, count=None):
RuntimeError is raised in case there is no way RuntimeError is raised in case there is no way
to finish activities. to finish activities.
""" """
activity_tool = self.getPortalObject().portal_activities
assert not (
activity_tool.isSubscribed()
and getCurrentNode() in activity_tool.getProcessingNodeList())
if count is not None: # BBB if count is not None: # BBB
# completely arbitrary conversion factor: count used to default to 1000 # completely arbitrary conversion factor: count used to default to 1000
# and I (just as arbitrarily) converted that into a 100s default maximum # and I (just as arbitrarily) converted that into a 100s default maximum
# tolerable wait delay before bailing. # tolerable wait delay before bailing.
delay = count / 10. delay = count / 10.
deadline = time.time() + delay deadline = time.time() + delay
activity_tool = self.getPortalObject().portal_activities
for call_count in itertools.count(): for call_count in itertools.count():
x = activity_tool.getMessageList() x = activity_tool.getMessageList()
if not x: if not x:
......
...@@ -420,6 +420,9 @@ class ERP5TypeFunctionalTestCase(ERP5TypeTestCase): ...@@ -420,6 +420,9 @@ class ERP5TypeFunctionalTestCase(ERP5TypeTestCase):
# create browser_id_manager # create browser_id_manager
if not "browser_id_manager" in self.portal.objectIds(): if not "browser_id_manager" in self.portal.objectIds():
self.portal.manage_addProduct['Sessions'].constructBrowserIdManager() self.portal.manage_addProduct['Sessions'].constructBrowserIdManager()
# unsubscribe from activities, we'll use Zuite_waitForActivities to
# process activities
self.portal.portal_activities.unsubscribe()
self.commit() self.commit()
self.setSystemPreference() self.setSystemPreference()
# non-recursive results clean of portal_tests/ or portal_tests/``run_only`` # non-recursive results clean of portal_tests/ or portal_tests/``run_only``
......
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