Commit 493bd0f2 authored by Hardik Juneja's avatar Hardik Juneja

CMFActivity: add tests

parent 03a84340
......@@ -37,6 +37,7 @@ from Products.ERP5Type.Base import Base
from Products.CMFActivity.Activity.SQLBase import INVOKE_ERROR_STATE
from Products.CMFActivity.Activity.Queue import VALIDATION_ERROR_DELAY
from Products.CMFActivity.Activity.SQLDict import SQLDict
from Products.CMFActivity.Activity.SQLJoblib import SQLJoblib, sqljoblib_hash
import Products.CMFActivity.ActivityTool
from Products.CMFActivity.Errors import ActivityPendingError, ActivityFlushError
from erp5.portal_type import Organisation
......@@ -84,7 +85,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
"""
Return the list of business templates.
"""
return ('erp5_base',)
return ('erp5_base', 'erp5_joblib')
def getCategoriesTool(self):
return getattr(self.getPortal(), 'portal_categories', None)
......@@ -404,6 +405,45 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
message_list = portal.portal_activities.getMessageList()
self.assertEqual(len(message_list),0)
def TryActiveProcessWithResultDictActivated(self, activity):
"""
Try to store the result inside an active process using result list
"""
portal = self.getPortal()
organisation = portal.organisation._getOb(self.company_id)
organisation._setTitle(self.title1)
active_process = portal.portal_activities.newActiveProcess()
self.assertEqual(self.title1,organisation.getTitle())
organisation.activate(activity=activity,active_process=active_process)._setTitle(self.title2)
# Needed so that the follow up messages which uses other queues
# are commited into the queue
self.commit()
portal.portal_activities.distribute()
portal.portal_activities.tic()
# Test getResultDict API
result_dict = active_process.getResultDict()
self.assertEqual(result_dict[sqljoblib_hash((self.title2, ))].method_id, '_setTitle')
self.assertEqual(self.title2,organisation.getTitle())
message_list = portal.portal_activities.getMessageList()
self.assertEqual(len(message_list),0)
# Post SQLjoblib tasks with explicit signature
organisation.activate(activity=activity,active_process=active_process, signature=1).getTitle()
organisation.activate(activity=activity,active_process=active_process, signature=2).getTitle()
organisation.activate(activity=activity,active_process=active_process, signature=3).getTitle()
self.commit()
portal.portal_activities.distribute()
portal.portal_activities.tic()
self.assertEqual(result_dict[1].method_id, 'getTitle')
self.assertEqual(result_dict[2].method_id, 'getTitle')
self.assertEqual(result_dict[3].method_id, 'getTitle')
message_list = portal.portal_activities.getMessageList()
self.assertEqual(len(message_list),0)
def TryMethodAfterMethod(self, activity):
"""
Ensure the order of an execution by a method id
......@@ -714,6 +754,15 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
LOG('Testing... ',0,message)
self.DeferredSetTitleActivity('SQLQueue')
def test_03_DeferredSetTitleSQLJoblib(self, quiet=0, run=run_all_test):
# Test if we can add a complete sales order
if not run: return
if not quiet:
message = '\nTest Deferred Set Title SQLJoblib '
ZopeTestCase._print(message)
LOG('Testing... ',0,message)
self.DeferredSetTitleActivity('SQLJoblib')
def test_05_InvokeAndCancelSQLDict(self, quiet=0, run=run_all_test):
# Test if we can add a complete sales order
if not run: return
......@@ -732,6 +781,15 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
LOG('Testing... ',0,message)
self.InvokeAndCancelActivity('SQLQueue')
def test_07_InvokeAndCancelSQLJoblib(self, quiet=0, run=run_all_test):
# Test if we can add a complete sales order
if not run: return
if not quiet:
message = '\nTest Invoke And Cancel SQLJoblib '
ZopeTestCase._print(message)
LOG('Testing... ',0,message)
self.InvokeAndCancelActivity('SQLJoblib')
def test_09_CallOnceWithSQLDict(self, quiet=0, run=run_all_test):
# Test if we call methods only once
if not run: return
......@@ -750,6 +808,15 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
LOG('Testing... ',0,message)
self.CallOnceWithActivity('SQLQueue')
def test_11_CallOnceWithSQLJoblib(self, quiet=0, run=run_all_test):
# Test if we call methods only once
if not run: return
if not quiet:
message = '\nCall Once With SQLJoblib '
ZopeTestCase._print(message)
LOG('Testing... ',0,message)
self.CallOnceWithActivity('SQLJoblib')
def test_13_TryMessageWithErrorOnSQLDict(self, quiet=0, run=run_all_test):
# Test if we call methods only once
if not run: return
......@@ -767,6 +834,15 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
ZopeTestCase._print(message)
LOG('Testing... ',0,message)
self.TryMessageWithErrorOnActivity('SQLQueue')
def test_15_TryMessageWithErrorOnSQLJoblib(self, quiet=0, run=run_all_test):
# Test if we call methods only once
if not run: return
if not quiet:
message = '\nTry Message With Error On SQL Joblib '
ZopeTestCase._print(message)
LOG('Testing... ',0,message)
self.TryMessageWithErrorOnActivity('SQLJoblib')
def test_17_TryFlushActivityWithSQLDict(self, quiet=0, run=run_all_test):
# Test if we call methods only once
......@@ -786,6 +862,15 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
LOG('Testing... ',0,message)
self.TryFlushActivity('SQLQueue')
def test_19_TryFlushActivityWithSQLJoblib(self, quiet=0, run=run_all_test):
# Test if we call methods only once
if not run: return
if not quiet:
message = '\nTry Flush Activity With SQL Joblib '
ZopeTestCase._print(message)
LOG('Testing... ',0,message)
self.TryFlushActivity('SQLJoblib')
def test_21_TryActivateInsideFlushWithSQLDict(self, quiet=0, run=run_all_test):
# Test if we call methods only once
if not run: return
......@@ -804,6 +889,15 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
LOG('Testing... ',0,message)
self.TryActivateInsideFlush('SQLQueue')
def test_23_TryActivateInsideFlushWithSQLQueue(self, quiet=0, run=run_all_test):
# Test if we call methods only once
if not run: return
if not quiet:
message = '\nTry Activate Inside Flush With SQL Joblib '
ZopeTestCase._print(message)
LOG('Testing... ',0,message)
self.TryActivateInsideFlush('SQLJoblib')
def test_25_TryTwoMethodsWithSQLDict(self, quiet=0, run=run_all_test):
# Test if we call methods only once
if not run: return
......@@ -822,6 +916,15 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
LOG('Testing... ',0,message)
self.TryTwoMethods('SQLQueue')
def test_27_TryTwoMethodsWithSQLJoblib(self, quiet=0, run=run_all_test):
# Test if we call methods only once
if not run: return
if not quiet:
message = '\nTry Two Methods With SQL Joblib '
ZopeTestCase._print(message)
LOG('Testing... ',0,message)
self.TryTwoMethods('SQLJoblib')
def test_29_TryTwoMethodsAndFlushThemWithSQLDict(self, quiet=0, run=run_all_test):
# Test if we call methods only once
if not run: return
......@@ -840,6 +943,16 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
LOG('Testing... ',0,message)
self.TryTwoMethodsAndFlushThem('SQLQueue')
def test_31_TryTwoMethodsAndFlushThemWithSQLJoblib(self, quiet=0, run=run_all_test):
# Test if we call methods only once
if not run: return
if not quiet:
message = '\nTry Two Methods And Flush Them With SQL Joblib '
ZopeTestCase._print(message)
LOG('Testing... ',0,message)
self.TryTwoMethodsAndFlushThem('SQLJoblib')
def test_33_TryActivateFlushActivateTicWithSQLDict(self, quiet=0, run=run_all_test):
# Test if we call methods only once
if not run: return
......@@ -904,6 +1017,15 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
LOG('Testing... ',0,message)
self.DeferredSetTitleWithRenamedObject('SQLQueue')
def test_44_TryRenameObjectWithSQLJoblib(self, quiet=0, run=run_all_test):
# Test if we call methods only once
if not run: return
if not quiet:
message = '\nTry Rename Object With SQL Joblib '
ZopeTestCase._print(message)
LOG('Testing... ',0,message)
self.DeferredSetTitleWithRenamedObject('SQLJoblib')
def test_46_TryActiveProcessWithSQLDict(self, quiet=0, run=run_all_test):
# Test if we call methods only once
if not run: return
......@@ -922,6 +1044,15 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
LOG('Testing... ',0,message)
self.TryActiveProcess('SQLQueue')
def test_47_TryActiveProcessWithSQLJoblib(self, quiet=0, run=run_all_test):
# Test if we call methods only once
if not run: return
if not quiet:
message = '\nTry Active Process With SQL Joblib '
ZopeTestCase._print(message)
LOG('Testing... ',0,message)
self.TryActiveProcessWithResultDictActivated('SQLJoblib')
def test_54_TryAfterMethodIdWithSQLDict(self, quiet=0, run=run_all_test):
# Test if after_method_id can be used
if not run: return
......@@ -940,7 +1071,16 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
LOG('Testing... ',0,message)
self.TryMethodAfterMethod('SQLQueue')
def test_56_TryCallActivityWithRightUser(self, quiet=0, run=run_all_test):
def test_56_TryAfterMethodIdWithSQLJoblib(self, quiet=0, run=run_all_test):
# Test if after_method_id can be used
if not run: return
if not quiet:
message = '\nTry Active Method After Another Activate Method With SQLJoblib'
ZopeTestCase._print(message)
LOG('Testing... ',0,message)
self.TryMethodAfterMethod('SQLJoblib')
def test_57_TryCallActivityWithRightUser(self, quiet=0, run=run_all_test):
# Test if me execute methods with the right user
# This should be independant of the activity used
if not run: return
......@@ -986,7 +1126,16 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
LOG('Testing... ',0,message)
self.TryAfterTag('SQLQueue')
def test_61_CheckSchedulingWithSQLDict(self, quiet=0, run=run_all_test):
def test_61_TryAfterTagWithSQLJoblib(self, quiet=0, run=run_all_test):
# Test if after_tag can be used
if not run: return
if not quiet:
message = '\nTry After Tag With SQL Joblib'
ZopeTestCase._print(message)
LOG('Testing... ',0,message)
self.TryAfterTag('SQLJoblib')
def test_62_CheckSchedulingWithSQLDict(self, quiet=0, run=run_all_test):
# Test if scheduling is correct with SQLDict
if not run: return
if not quiet:
......@@ -995,7 +1144,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
LOG('Testing... ',0,message)
self.CheckScheduling('SQLDict')
def test_62_CheckSchedulingWithSQLQueue(self, quiet=0, run=run_all_test):
def test_63_CheckSchedulingWithSQLQueue(self, quiet=0, run=run_all_test):
# Test if scheduling is correct with SQLQueue
if not run: return
if not quiet:
......@@ -1004,7 +1153,16 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
LOG('Testing... ',0,message)
self.CheckScheduling('SQLQueue')
def test_61_CheckSchedulingAfterTagListWithSQLDict(self, quiet=0, run=run_all_test):
def test_64_CheckSchedulingWithSQLJoblib(self, quiet=0, run=run_all_test):
# Test if scheduling is correct with SQLQueue
if not run: return
if not quiet:
message = '\nCheck Scheduling With SQL Joblib'
ZopeTestCase._print(message)
LOG('Testing... ',0,message)
self.CheckScheduling('SQLJoblib')
def test_65_CheckSchedulingAfterTagListWithSQLDict(self, quiet=0, run=run_all_test):
# Test if scheduling is correct with SQLDict
if not run: return
if not quiet:
......@@ -1013,7 +1171,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
LOG('Testing... ',0,message)
self.CheckSchedulingAfterTagList('SQLDict')
def test_62_CheckSchedulingWithAfterTagListSQLQueue(self, quiet=0, run=run_all_test):
def test_66_CheckSchedulingWithAfterTagListSQLQueue(self, quiet=0, run=run_all_test):
# Test if scheduling is correct with SQLQueue
if not run: return
if not quiet:
......@@ -1022,6 +1180,15 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
LOG('Testing... ',0,message)
self.CheckSchedulingAfterTagList('SQLQueue')
def test_67_CheckSchedulingWithAfterTagListSQLJoblib(self, quiet=0, run=run_all_test):
# Test if scheduling is correct with SQLQueue
if not run: return
if not quiet:
message = '\nCheck Scheduling After Tag List With SQL Joblib'
ZopeTestCase._print(message)
LOG('Testing... ',0,message)
self.CheckSchedulingAfterTagList('SQLJoblib')
def flushAllActivities(self, silent=0, loop_size=1000):
"""Executes all messages until the queue only contains failed
messages.
......@@ -1043,7 +1210,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
if not silent:
self.fail('flushAllActivities maximum loop count reached')
def test_65_TestMessageValidationAndFailedActivities(self,
def test_66_TestMessageValidationAndFailedActivities(self,
quiet=0, run=run_all_test):
"""after_method_id and failed activities.
......@@ -1065,13 +1232,12 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
obj = self.getPortal().organisation_module.newContent(
portal_type='Organisation',
title=original_title)
# Monkey patch Organisation to add a failing method
def failingMethod(self):
raise ValueError, 'This method always fail'
Organisation.failingMethod = failingMethod
activity_list = ['SQLQueue', 'SQLDict', ]
activity_list = ['SQLQueue', 'SQLDict', 'SQLJoblib']
for activity in activity_list:
# reset
activity_tool.manageClearActivities()
......@@ -1086,7 +1252,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
full_message_list = activity_tool.getMessageList()
remaining_messages = [a for a in full_message_list if a.method_id !=
'failingMethod']
if len(full_message_list) != 2:
if len(full_message_list) != 3:
self.fail('failingMethod should not have been flushed')
if len(remaining_messages) != 0:
self.fail('Activity tool should have no other remaining messages')
......@@ -1100,7 +1266,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
full_message_list = activity_tool.getMessageList()
remaining_messages = [a for a in full_message_list if a.method_id !=
'failingMethod']
if len(full_message_list) != 3:
if len(full_message_list) != 4:
self.fail('failingMethod should not have been flushed')
if len(remaining_messages) != 1:
self.fail('Activity tool should have one blocked setTitle activity')
......@@ -1108,7 +1274,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
['failingMethod'])
self.assertEqual(obj.getTitle(), original_title)
def test_66_TestCountMessageWithTagWithSQLDict(self, quiet=0, run=run_all_test):
def test_68_TestCountMessageWithTagWithSQLDict(self, quiet=0, run=run_all_test):
"""
Test new countMessageWithTag function with SQLDict.
"""
......@@ -1119,7 +1285,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
LOG('Testing... ', 0, message)
self.CheckCountMessageWithTag('SQLDict')
def test_67_TestCancelFailedActiveObject(self, quiet=0, run=run_all_test):
def test_69_TestCancelFailedActiveObject(self, quiet=0, run=run_all_test):
"""Cancel an active object to make sure that it does not refer to
a persistent object.
......@@ -1170,7 +1336,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
self.commit()
self.assertEqual(len(activity_tool.getMessageList()), 0)
def test_68_RetryMessageExecution(self, quiet=0):
def test_70_RetryMessageExecution(self, quiet=0):
if not quiet:
message = '\nCheck number of executions of failing activities'
ZopeTestCase._print(message)
......@@ -1190,7 +1356,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
raise ConflictError if conflict else Exception
def check(retry_list, **activate_kw):
fail = retry_list[-1][0] is not None and 1 or 0
for activity in 'SQLDict', 'SQLQueue':
for activity in 'SQLDict', 'SQLQueue', 'SQLJoblib':
exec_count[0] = 0
activity_tool.activate(activity=activity, priority=priority(1,6),
**activate_kw).doSomething(retry_list)
......@@ -1231,7 +1397,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
del activity_tool.__class__.doSomething
self.assertFalse(activity_tool.getMessageList())
def test_70_TestConflictErrorsWhileValidatingWithSQLDict(self, quiet=0, run=run_all_test):
def test_71_TestConflictErrorsWhileValidatingWithSQLDict(self, quiet=0, run=run_all_test):
"""
Test if conflict errors spoil out active objects with SQLDict.
"""
......@@ -1242,7 +1408,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
LOG('Testing... ', 0, message)
self.TryConflictErrorsWhileValidating('SQLDict')
def test_71_TestConflictErrorsWhileValidatingWithSQLQueue(self, quiet=0, run=run_all_test):
def test_72_TestConflictErrorsWhileValidatingWithSQLQueue(self, quiet=0, run=run_all_test):
"""
Test if conflict errors spoil out active objects with SQLQueue.
"""
......@@ -1253,7 +1419,29 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
LOG('Testing... ', 0, message)
self.TryConflictErrorsWhileValidating('SQLQueue')
def test_72_TestErrorsWhileFinishingCommitDBWithSQLDict(self, quiet=0, run=run_all_test):
def test_73_TestConflictErrorsWhileValidatingWithSQLJoblib(self, quiet=0, run=run_all_test):
"""
Test if conflict errors spoil out active objects with SQLJoblib.
"""
if not run: return
if not quiet:
message = '\nTest Conflict Errors While Validating With SQLJoblib'
ZopeTestCase._print(message)
LOG('Testing... ', 0, message)
self.TryConflictErrorsWhileValidating('SQLJoblib')
def test_74_TestConflictErrorsWhileValidatingWithSQLJoblib(self, quiet=0, run=run_all_test):
"""
Test if conflict errors spoil out active objects with SQLJoblib.
"""
if not run: return
if not quiet:
message = '\nTest Conflict Errors While Validating With SQLJoblib'
ZopeTestCase._print(message)
LOG('Testing... ', 0, message)
self.TryConflictErrorsWhileValidating('SQLJoblib')
def test_75_TestErrorsWhileFinishingCommitDBWithSQLDict(self, quiet=0, run=run_all_test):
"""
"""
if not run: return
......@@ -1263,7 +1451,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
LOG('Testing... ', 0, message)
self.TryErrorsWhileFinishingCommitDB('SQLDict')
def test_73_TestErrorsWhileFinishingCommitDBWithSQLQueue(self, quiet=0, run=run_all_test):
def test_76_TestErrorsWhileFinishingCommitDBWithSQLQueue(self, quiet=0, run=run_all_test):
"""
"""
if not run: return
......@@ -1273,7 +1461,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
LOG('Testing... ', 0, message)
self.TryErrorsWhileFinishingCommitDB('SQLQueue')
def test_74_TryFlushActivityWithAfterTagSQLDict(self, quiet=0, run=run_all_test):
def test_77_TryFlushActivityWithAfterTagSQLDict(self, quiet=0, run=run_all_test):
# Test if after_tag can be used
if not run: return
if not quiet:
......@@ -1282,7 +1470,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
LOG('Testing... ',0,message)
self.TryFlushActivityWithAfterTag('SQLDict')
def test_75_TryFlushActivityWithAfterTagWithSQLQueue(self, quiet=0, run=run_all_test):
def test_78_TryFlushActivityWithAfterTagWithSQLQueue(self, quiet=0, run=run_all_test):
# Test if after_tag can be used
if not run: return
if not quiet:
......@@ -1291,7 +1479,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
LOG('Testing... ',0,message)
self.TryFlushActivityWithAfterTag('SQLQueue')
def test_76_ActivateKwForNewContent(self, quiet=0, run=run_all_test):
def test_79_ActivateKwForNewContent(self, quiet=0, run=run_all_test):
if not run: return
if not quiet:
message = '\nCheck reindex message uses activate_kw passed to newContent'
......@@ -1308,7 +1496,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
self.assertEqual(m.activity_kw.get('tag'), 'The Tag')
def test_77_FlushAfterMultipleActivate(self, quiet=0, run=run_all_test):
def test_80_FlushAfterMultipleActivate(self, quiet=0, run=run_all_test):
if not run: return
if not quiet:
message = '\nCheck all message are flushed in SQLDict'
......@@ -1345,7 +1533,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
self.commit()
self.assertEqual(len(activity_tool.getMessageList()), 0)
def test_78_IsMessageRegisteredSQLDict(self, quiet=0, run=run_all_test):
def test_81_IsMessageRegisteredSQLDict(self, quiet=0, run=run_all_test):
"""
This test tests behaviour of IsMessageRegistered method.
"""
......@@ -1356,7 +1544,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
LOG('Testing... ',0,message)
self.checkIsMessageRegisteredMethod('SQLDict')
def test_79_AbortTransactionSynchronously(self, quiet=0, run=run_all_test):
def test_82_AbortTransactionSynchronously(self, quiet=0, run=run_all_test):
"""
This test checks if transaction.abort() synchronizes connections. It
didn't do so back in Zope 2.7
......@@ -1435,7 +1623,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
message_list = portal.portal_activities.getMessageList()
self.assertEqual(len(message_list),5)
portal.portal_activities.tic()
expected = dict(SQLDict=1, SQLQueue=5)[activity]
expected = dict(SQLDict=1, SQLQueue=5, SQLJoblib=1)[activity]
self.assertEqual(expected, organisation.getFoobar())
......@@ -1466,27 +1654,34 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
message_list = portal.portal_activities.getMessageList()
self.assertEqual(len(message_list),20)
portal.portal_activities.tic()
self.assertEqual(dict(SQLDict=11, SQLQueue=60)[activity],
self.assertEqual(dict(SQLDict=11, SQLQueue=60, SQLJoblib=11)[activity],
organisation.getFoobar())
self.assertEqual(dict(SQLDict=[1, 1, 1], SQLQueue=[5, 5, 10])[activity],
self.assertEqual(dict(SQLDict=[1, 1, 1], SQLQueue=[5, 5, 10], SQLJoblib=[1,1,1])[activity],
sorted(foobar_list))
message_list = portal.portal_activities.getMessageList()
self.assertEqual(len(message_list), 0)
def test_80a_CallWithGroupIdParamaterSQLDict(self, quiet=0, run=run_all_test):
def test_83a_CallWithGroupIdParamaterSQLDict(self, quiet=0, run=run_all_test):
"""
Test that group_id parameter is used to separate execution of the same method
"""
self.callWithGroupIdParamater('SQLDict', quiet=quiet, run=run)
def test_80b_CallWithGroupIdParamaterSQLQueue(self, quiet=0,
def test_83b_CallWithGroupIdParamaterSQLQueue(self, quiet=0,
run=run_all_test):
"""
Test that group_id parameter is used to separate execution of the same method
"""
self.callWithGroupIdParamater('SQLQueue', quiet=quiet, run=run)
def test_81_ActivateKwForWorkflowTransition(self, quiet=0, run=run_all_test):
def test_83c_CallWithGroupIdParamaterSQLJoblib(self, quiet=0,
run=run_all_test):
"""
Test that group_id parameter is used to separate execution of the same method
"""
self.callWithGroupIdParamater('SQLJoblib', quiet=quiet, run=run)
def test_84_ActivateKwForWorkflowTransition(self, quiet=0, run=run_all_test):
"""
Test call of a workflow transition with activate_kw parameter propagate them
"""
......@@ -1505,7 +1700,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
for m in messages_for_o1:
self.assertEqual(m.activity_kw.get('tag'), 'The Tag')
def test_82_LossOfVolatileAttribute(self, quiet=0, run=run_all_test):
def test_85_LossOfVolatileAttribute(self, quiet=0, run=run_all_test):
"""
Test that the loss of volatile attribute doesn't loose activities
"""
......@@ -1636,17 +1831,17 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
finally:
del Organisation.failingMethod
def test_90_userNotificationOnActivityFailureWithSQLDict(self, quiet=0, run=run_all_test):
def test_90_userNotificationOnActivityFailureWithSQLJoblib(self, quiet=0, run=run_all_test):
"""
Check that a user notification method is called on message when activity
fails and will not be tried again.
"""
if not run: return
if not quiet:
message = '\nCheck user notification sent on activity final error (SQLDict)'
message = '\nCheck user notification sent on activity final error (SQLJoblib)'
ZopeTestCase._print(message)
LOG('Testing... ',0,message)
self.TryUserNotificationOnActivityFailure('SQLDict')
self.TryUserNotificationOnActivityFailure('SQLJoblib')
def test_91_userNotificationOnActivityFailureWithSQLQueue(self, quiet=0, run=run_all_test):
"""
......@@ -1703,6 +1898,17 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
LOG('Testing... ',0,message)
self.TryUserNotificationRaise('SQLQueue')
def test_94_userNotificationRaiseWithSQLJoblib(self, quiet=0, run=run_all_test):
"""
Check that activities are not left with processing=1 when notifyUser raises.
"""
if not run: return
if not quiet:
message = '\nCheck that activities are not left with processing=1 when notifyUser raises (SQLJoblib)'
ZopeTestCase._print(message)
LOG('Testing... ',0,message)
self.TryUserNotificationRaise('SQLJoblib')
def TryActivityRaiseInCommitDoesNotStallActivityConection(self, activity):
"""
Check that an activity which commit raises (as would a regular conflict
......@@ -1813,7 +2019,15 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
LOG('Testing... ',0,message)
self.TryChangeSkinInActivity('SQLQueue')
def test_102_1_CheckSQLDictDoesNotDeleteSimilaritiesBeforeExecution(self, quiet=0, run=run_all_test):
def test_102_TryChangeSkinInActivitySQLJoblib(self, quiet=0, run=run_all_test):
if not run: return
if not quiet:
message = '\nTry ChangeSkin In Activity (SQLJoblib)'
ZopeTestCase._print(message)
LOG('Testing... ',0,message)
self.TryChangeSkinInActivity('SQLJoblib')
def test_103_1_CheckSQLDictDoesNotDeleteSimilaritiesBeforeExecution(self, quiet=0, run=run_all_test):
"""
Test that SQLDict does not delete similar messages which have the same
method_id and path but a different tag before execution.
......@@ -1845,7 +2059,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
finally:
del activity_tool.__class__.doSomething
def test_102_2_CheckSQLDictDeleteDuplicatesBeforeExecution(self, quiet=0, run=run_all_test):
def test_103_2_CheckSQLDictDeleteDuplicatesBeforeExecution(self, quiet=0, run=run_all_test):
"""
Test that SQLDict delete the same messages before execution if messages
has the same method_id and path and tag.
......@@ -1880,7 +2094,42 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
finally:
del activity_tool.__class__.doSomething
def test_102_3_CheckSQLDictDistributeWithSerializationTagAndGroupMethodId(
def test_103_3_CheckSQLJoblibDeleteDuplicatesBeforeExecution(self, quiet=0, run=run_all_test):
"""
Test that SQLJoblib delete the same messages before execution if messages
has the same method_id and path and tag and signature.
"""
if not run: return
if not quiet:
message = '\nCheck duplicates are deleted before execution of original message (SQLJoblib)'
ZopeTestCase._print(message)
LOG('Testing... ',0,message)
activity_tool = self.getActivityTool()
marker = []
def doSomething(self, other_tag):
marker.append(self.countMessage(tag=other_tag))
activity_tool.__class__.doSomething = doSomething
try:
# Adds two same activities.
activity_tool.activate(activity='SQLJoblib', after_tag='foo', priority=2,
tag='a', signature=555666).doSomething(other_tag='a')
self.commit()
uid1, = [x.uid for x in activity_tool.getMessageList()]
activity_tool.activate(activity='SQLJoblib', after_tag='bar', priority=1,
tag='a', signature=555666).doSomething(other_tag='a')
self.commit()
self.assertEqual(len(activity_tool.getMessageList()), 2)
activity_tool.distribute()
# After distribute, duplicate is deleted.
uid2, = [x.uid for x in activity_tool.getMessageList()]
self.assertNotEqual(uid1, uid2)
activity_tool.tic()
self.assertEqual(len(activity_tool.getMessageList()), 0)
self.assertEqual(marker, [1])
finally:
del activity_tool.__class__.doSomething
def test_103_4_CheckSQLDictDistributeWithSerializationTagAndGroupMethodId(
self, quiet=0):
"""
Distribuation was at some point buggy with this scenario when there was
......@@ -1904,7 +2153,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
self.tic()
self.assertEqual(len(activity_tool.getMessageList()), 0)
def test_103_interQueuePriorities(self, quiet=0, run=run_all_test):
def test_104_interQueuePriorities(self, quiet=0, run=run_all_test):
"""
Important note: there is no way to really reliably check that this
feature is correctly implemented, as activity execution order is
......@@ -1984,7 +2233,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
finally:
del document.__class__.doSomething
def test_104_activityRuntimeEnvironmentSQLDict(self, quiet=0, run=run_all_test):
def test_105_activityRuntimeEnvironmentSQLDict(self, quiet=0, run=run_all_test):
if not run: return
if not quiet:
message = '\nCheck ActivityRuntimeEnvironment (SQLDict)'
......@@ -1992,7 +2241,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
LOG('Testing... ',0,message)
self.CheckActivityRuntimeEnvironment('SQLDict')
def test_105_activityRuntimeEnvironmentSQLQueue(self, quiet=0, run=run_all_test):
def test_106_activityRuntimeEnvironmentSQLQueue(self, quiet=0, run=run_all_test):
if not run: return
if not quiet:
message = '\nCheck ActivityRuntimeEnvironment (SQLQueue)'
......@@ -2000,6 +2249,14 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
LOG('Testing... ',0,message)
self.CheckActivityRuntimeEnvironment('SQLQueue')
def test_107_activityRuntimeEnvironmentSQLJoblib(self, quiet=0, run=run_all_test):
if not run: return
if not quiet:
message = '\nCheck ActivityRuntimeEnvironment (SQLJoblib)'
ZopeTestCase._print(message)
LOG('Testing... ',0,message)
self.CheckActivityRuntimeEnvironment('SQLJoblib')
def CheckSerializationTag(self, activity):
organisation = self.getPortal().organisation_module.newContent(portal_type='Organisation')
self.tic()
......@@ -2051,7 +2308,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
self.tic()
self.assertEqual(len(activity_tool.getMessageList()), 0)
def test_106_checkSerializationTagSQLDict(self, quiet=0, run=run_all_test):
def test_108_checkSerializationTagSQLDict(self, quiet=0, run=run_all_test):
if not run: return
if not quiet:
message = '\nCheck serialization tag (SQLDict)'
......@@ -2059,7 +2316,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
LOG('Testing... ',0,message)
self.CheckSerializationTag('SQLDict')
def test_107_checkSerializationTagSQLQueue(self, quiet=0, run=run_all_test):
def test_109_checkSerializationTagSQLQueue(self, quiet=0, run=run_all_test):
if not run: return
if not quiet:
message = '\nCheck serialization tag (SQLQueue)'
......@@ -2067,7 +2324,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
LOG('Testing... ',0,message)
self.CheckSerializationTag('SQLQueue')
def test_108_testAbsoluteUrl(self):
def test_110_testAbsoluteUrl(self):
# Tests that absolute_url works in activities. The URL generation is based
# on REQUEST information when the method was activated.
request = self.portal.REQUEST
......@@ -2319,7 +2576,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
self.assertFalse(active_process.hasActivity())
def test(obj, **kw):
for activity in ('SQLDict', 'SQLQueue'):
for activity in ('SQLDict', 'SQLQueue', 'SQLJoblib'):
active_object.activate(activity=activity, **kw).getTitle()
self.commit()
self.assertTrue(obj.hasActivity(), activity)
......@@ -2367,6 +2624,9 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
def test_hasErrorActivity_error_SQLDict(self):
self._test_hasErrorActivity_error('SQLDict')
def test_hasErrorActivity_error_SQLJoblib(self):
self._test_hasErrorActivity_error('SQLJoblib')
def _test_hasErrorActivity(self, activity):
active_object = self.portal.organisation_module.newContent(
portal_type='Organisation')
......@@ -2399,6 +2659,9 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
def test_hasErrorActivity_SQLDict(self):
self._test_hasErrorActivity('SQLDict')
def test_hasErrorActivity_SQLJoblib(self):
self._test_hasErrorActivity('SQLJoblib')
def test_active_object_hasActivity_does_not_catch_exceptions(self):
"""
Some time ago, hasActivity was doing a silent try/except, and this was
......@@ -2438,7 +2701,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
self.__call_count += 1
o = self.portal.organisation_module.newContent(portal_type='Organisation')
for activity in "SQLDict", "SQLQueue":
for activity in "SQLDict", "SQLQueue", "SQLJoblib":
self.__call_count = 0
try:
for i in xrange(10):
......@@ -2534,7 +2797,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
activity_tool = self.portal.portal_activities
activity_tool.__class__.doSomething = processed.append
try:
for activity in 'SQLDict', 'SQLQueue':
for activity in 'SQLDict', 'SQLQueue', 'SQLJoblib':
activity_tool.activate(activity=activity).doSomething(activity)
self.commit()
# Make first commit in dequeueMessage raise
......@@ -2640,6 +2903,17 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
LOG('Testing... ',0,message)
self.TryNotificationSavedOnEventLogWhenNotifyUserRaises('SQLQueue')
def test_120_userNotificationSavedOnEventLogWhenNotifyUserRaisesWithSQLJoblib(self, quiet=0, run=run_all_test):
"""
Check the error is saved on event log even if the mail notification is not sent.
"""
if not run: return
if not quiet:
message = '\nCheck the error is saved on event log even if the mail notification is not sent (SQLJoblib)'
ZopeTestCase._print(message)
LOG('Testing... ',0,message)
self.TryNotificationSavedOnEventLogWhenNotifyUserRaises('SQLJoblib')
def TryUserMessageContainingNoTracebackIsStillSent(self, activity):
portal = self.getPortalObject()
activity_tool = self.getActivityTool()
......@@ -2672,7 +2946,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
Message.notifyUser = original_notifyUser
delattr(Organisation, 'failingMethod')
def test_120_sendMessageWithNoTracebackWithSQLQueue(self, quiet=0, run=run_all_test):
def test_121_sendMessageWithNoTracebackWithSQLQueue(self, quiet=0, run=run_all_test):
if not run: return
if not quiet:
message = '\nCheck that message with no traceback is still sent (SQLQueue)'
......@@ -2680,7 +2954,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
LOG('Testing... ',0,message)
self.TryUserMessageContainingNoTracebackIsStillSent('SQLQueue')
def test_121_sendMessageWithNoTracebackWithSQLDict(self, quiet=0, run=run_all_test):
def test_122_sendMessageWithNoTracebackWithSQLDict(self, quiet=0, run=run_all_test):
if not run: return
if not quiet:
message = '\nCheck that message with no traceback is still sent (SQLDict)'
......@@ -2688,6 +2962,14 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
LOG('Testing... ',0,message)
self.TryUserMessageContainingNoTracebackIsStillSent('SQLDict')
def test_123_sendMessageWithNoTracebackWithSQLJoblib(self, quiet=0, run=run_all_test):
if not run: return
if not quiet:
message = '\nCheck that message with no traceback is still sent (SQLJoblib)'
ZopeTestCase._print(message)
LOG('Testing... ',0,message)
self.TryUserMessageContainingNoTracebackIsStillSent('SQLJoblib')
def TryNotificationSavedOnEventLogWhenSiteErrorLoggerRaises(self, activity):
# Make sure that no active object is installed.
activity_tool = self.getPortal().portal_activities
......@@ -2731,7 +3013,15 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
del Organisation.failingMethod
self._ignore_log_errors()
def test_122_userNotificationSavedOnEventLogWhenSiteErrorLoggerRaisesWithSQLDict(self, quiet=0, run=run_all_test):
def test_124_userNotificationSavedOnEventLogWhenSiteErrorLoggerRaisesWithSQLJoblib(self, quiet=0, run=run_all_test):
if not run: return
if not quiet:
message = '\nCheck that message not saved in site error logger is not lost'
ZopeTestCase._print(message)
LOG('Testing... ',0,message)
self.TryNotificationSavedOnEventLogWhenSiteErrorLoggerRaises('SQLJoblib')
def test_125_userNotificationSavedOnEventLogWhenSiteErrorLoggerRaisesWithSQLDict(self, quiet=0, run=run_all_test):
if not run: return
if not quiet:
message = '\nCheck that message not saved in site error logger is not lost'
......@@ -2739,7 +3029,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
LOG('Testing... ',0,message)
self.TryNotificationSavedOnEventLogWhenSiteErrorLoggerRaises('SQLDict')
def test_123_userNotificationSavedOnEventLogWhenSiteErrorLoggerRaisesWithSQLQueue(self, quiet=0, run=run_all_test):
def test_126_userNotificationSavedOnEventLogWhenSiteErrorLoggerRaisesWithSQLQueue(self, quiet=0, run=run_all_test):
if not run: return
if not quiet:
message = '\nCheck that message not saved in site error logger is not lost'
......@@ -2747,7 +3037,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
LOG('Testing... ',0,message)
self.TryNotificationSavedOnEventLogWhenSiteErrorLoggerRaises('SQLQueue')
def test_124_checkConflictErrorAndNoRemainingActivities(self):
def test_127_checkConflictErrorAndNoRemainingActivities(self):
"""
When an activity creates several activities, make sure that all newly
created activities are not commited if there is ZODB Conflict error
......@@ -2779,7 +3069,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
finally:
SQLBase.MAX_MESSAGE_LIST_SIZE = MAX_MESSAGE_LIST_SIZE
def test_125_CheckDistributeWithSerializationTagAndGroupMethodId(self):
def test_128_CheckDistributeWithSerializationTagAndGroupMethodId(self):
activity_tool = self.portal.portal_activities
obj1 = activity_tool.newActiveProcess()
obj2 = activity_tool.newActiveProcess()
......@@ -2793,7 +3083,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
group_method_call_list.append(r)
activity_tool.__class__.doSomething = doSomething
try:
for activity in 'SQLDict', 'SQLQueue':
for activity in 'SQLDict', 'SQLQueue', 'SQLJoblib':
activity_kw = dict(activity=activity, serialization_tag=self.id(),
group_method_id='portal_activities/doSomething')
obj1.activate(**activity_kw).dummy(1, x=None)
......@@ -2816,13 +3106,14 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
activity_tool.tic()
self.assertEqual(group_method_call_list.pop(),
dict(SQLDict=[message2],
SQLQueue=[message1, message2])[activity])
SQLQueue=[message1, message2],
SQLJoblib=[message2])[activity])
self.assertFalse(group_method_call_list)
self.assertFalse(activity_tool.getMessageList())
finally:
del activity_tool.__class__.doSomething
def test_126_beforeCommitHook(self):
def test_129_beforeCommitHook(self):
"""
Check it is possible to activate an object from a before commit hook
"""
......@@ -2927,7 +3218,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
transaction.get().addBeforeCommitHook(_raise, (error,))
obj.__class__.doSomething = doSomething
try:
for activity in 'SQLDict', 'SQLQueue':
for activity in 'SQLDict', 'SQLQueue', 'SQLJoblib':
for conflict_error in False, True:
weakref_list = []
obj.activity_count = obj.on_error_count = 0
......@@ -3058,7 +3349,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
kw = {}
self._catch_log_errors(subsystem='CMFActivity')
try:
for kw['activity'] in 'SQLDict', 'SQLQueue':
for kw['activity'] in 'SQLDict', 'SQLQueue', 'SQLJoblib':
for kw['group_method_id'] in '', None:
obj = activity_tool.newActiveProcess()
self.tic()
......
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