Commit 2a5b5927 authored by Vincent Pelletier's avatar Vincent Pelletier

Alarms must not be blocked by failed activities, and though portal activities...

Alarms must not be blocked by failed activities, and though portal activities must provide a way to count "valid" pending activities without counting failed activities.
Add unit test at alarm document level.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@15138 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 6ff0f9bb
...@@ -8,13 +8,13 @@ class_name: ...@@ -8,13 +8,13 @@ class_name:
class_file: class_file:
</dtml-comment> </dtml-comment>
<params>path <params>path
method_id</params> method_id
only_valid</params>
SELECT count(path) as message_count FROM SELECT count(path) as message_count FROM
message message
<dtml-if "path or method_id">
WHERE WHERE
<dtml-if path> path = <dtml-sqlvar path type="string"></dtml-if> 1 = 1
<dtml-if path> AND path = <dtml-sqlvar path type="string"></dtml-if>
<dtml-if method_id>AND method_id = <dtml-sqlvar method_id type="string"></dtml-if> <dtml-if method_id>AND method_id = <dtml-sqlvar method_id type="string"></dtml-if>
</dtml-if> <dtml-if only_valid>AND processing_node > -2</dtml-if>
...@@ -8,12 +8,13 @@ class_name: ...@@ -8,12 +8,13 @@ class_name:
class_file: class_file:
</dtml-comment> </dtml-comment>
<params>path <params>path
method_id</params> method_id
only_valid</params>
SELECT count(path) as message_count FROM SELECT count(path) as message_count FROM
message_queue message_queue
<dtml-if "path or method_id">
WHERE WHERE
<dtml-if path> path = <dtml-sqlvar path type="string"></dtml-if> 1 = 1
<dtml-if path>AND path = <dtml-sqlvar path type="string"></dtml-if>
<dtml-if method_id>AND method_id = <dtml-sqlvar method_id type="string"></dtml-if> <dtml-if method_id>AND method_id = <dtml-sqlvar method_id type="string"></dtml-if>
</dtml-if> <dtml-if only_valid>AND processing_node > -2</dtml-if>
...@@ -264,7 +264,7 @@ class Alarm(XMLObject, PeriodicityMixin): ...@@ -264,7 +264,7 @@ class Alarm(XMLObject, PeriodicityMixin):
active or not. It is activated when it is doing some calculation with active or not. It is activated when it is doing some calculation with
activeSense or solve. activeSense or solve.
""" """
return self.hasActivity() return self.hasActivity(only_valid=1)
security.declareProtected(Permissions.ModifyPortalContent, 'activeSense') security.declareProtected(Permissions.ModifyPortalContent, 'activeSense')
def activeSense(self): def activeSense(self):
......
...@@ -422,6 +422,50 @@ class TestAlarm(ERP5TypeTestCase): ...@@ -422,6 +422,50 @@ class TestAlarm(ERP5TypeTestCase):
self.tic() self.tic()
self.assertEquals(active_process, alarm.getLastActiveProcess()) self.assertEquals(active_process, alarm.getLastActiveProcess())
def test_15_FailedAlarmsDoNotBlockFutureAlarms(self, quiet=0, run=run_all_test):
if not run: return
if not quiet:
message = 'Test Failed Alarms Do Not Block Future Alarms'
ZopeTestCase._print('\n%s ' % message)
LOG('Testing... ',0,message)
sense_method_id = 'Alarm_testSenseMethod'
skin_folder_id = 'custom'
skin_folder = self.getPortal().portal_skins[skin_folder_id]
skin_folder.manage_addProduct['PythonScripts'].manage_addPythonScript(id=sense_method_id)
# Make the sense method fail
skin_folder[sense_method_id].ZPythonScript_edit('*args,**kw', 'raise Exception')
del skin_folder
alarm = self.newAlarm()
now = DateTime()
alarm.setActiveSenseMethodId(sense_method_id)
self.assertEquals(alarm.isActive(), 0)
alarm.activeSense()
get_transaction().commit()
try:
self.tic()
except RuntimeError:
pass
else:
raise Exception, 'Tic did not raise though activity was supposed to fail'
# Check that the alarm is not considered active, although there is a remaining activity.
self.assertEquals(alarm.hasActivity(), 1)
self.assertEquals(alarm.isActive(), 0)
self.assertEquals(alarm.getLastActiveProcess(), None)
# Make the sense method succeed and leave a trace
self.getPortal().portal_skins[skin_folder_id][sense_method_id].ZPythonScript_edit('*args,**kw', 'context.newActiveProcess()')
alarm.activeSense()
get_transaction().commit()
# Note: this call to tic will not fail, because the same method on the same
# object is activated again in SQLDict. When the new message will be
# -successfully- processed, the previous -failed- message will get removed
# in the cleanup. This behaviour is logical if we consider that manually
# executing the failed message to get the error will lead to no error.
# But it can also be considered illogical if failed messages are supposed
# to be preserved for future analysis.
self.tic()
# Chen that the second alarm execution did happen
self.assertNotEquals(alarm.getLastActiveProcess(), None)
if __name__ == '__main__': if __name__ == '__main__':
framework() framework()
else: else:
......
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