[Erp5-report] r43067 leonardo - /erp5/trunk/products/ERP5Type/tests/ProcessingNodeTestCase.py

nobody at svn.erp5.org nobody at svn.erp5.org
Fri Feb 4 17:56:11 CET 2011


Author: leonardo
Date: Fri Feb  4 17:56:10 2011
New Revision: 43067

URL: http://svn.erp5.org?rev=43067&view=rev
Log:
allow unittest tic() not to process all messages. Useful for testing some activity race conditions

Modified:
    erp5/trunk/products/ERP5Type/tests/ProcessingNodeTestCase.py

Modified: erp5/trunk/products/ERP5Type/tests/ProcessingNodeTestCase.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/tests/ProcessingNodeTestCase.py?rev=43067&r1=43066&r2=43067&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/tests/ProcessingNodeTestCase.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/tests/ProcessingNodeTestCase.py [utf8] Fri Feb  4 17:56:10 2011
@@ -21,6 +21,8 @@ def patchActivityTool():
     setattr(ActivityTool, '_orig_' + name, orig_function)
     setattr(ActivityTool, name, function)
     function.__doc__ = orig_function.__doc__
+    # make life easier when inspecting the wrapper with ipython
+    function._original = orig_function
 
   # When a ZServer can't be started, the node name ends with ':' (no port).
   @patch
@@ -140,7 +142,7 @@ class ProcessingNodeTestCase(backportUni
                          % error_log[-1]
       self.fail(error_message)
 
-  def tic(self, verbose=0):
+  def tic(self, verbose=0, stop_condition=lambda message_list: False):
     """Execute pending activities"""
     # Some tests like testDeferredStyle require that we use self.getPortal()
     # instead of self.portal in order to setup current skin.
@@ -151,9 +153,11 @@ class ProcessingNodeTestCase(backportUni
         old_message_count = 0
         start = time.time()
       count = 1000
-      getMessageList = portal_activities.getMessageList
-      message_count = len(getMessageList(include_processing=1))
-      while message_count:
+      def getMessageList():
+        return portal_activities.getMessageList(include_processing=1)
+      message_list = getMessageList()
+      message_count = len(message_list)
+      while message_count and not stop_condition(message_list):
         if verbose and old_message_count != message_count:
           ZopeTestCase._print(' %i' % message_count)
           old_message_count = message_count
@@ -161,7 +165,8 @@ class ProcessingNodeTestCase(backportUni
         if Lifetime._shutdown_phase:
           # XXX CMFActivity contains bare excepts
           raise KeyboardInterrupt
-        message_count = len(getMessageList(include_processing=1))
+        message_list = getMessageList()
+        message_count = len(message_list)
         # This prevents an infinite loop.
         count -= 1
         if count == 0:



More information about the Erp5-report mailing list