[Zope-CVS] CVS: Products/Scheduler/tests - testScheduler.py:1.4

Chris McDonough chrism@zope.com
Mon, 7 Jul 2003 17:32:28 -0400


Update of /cvs-repository/Products/Scheduler/tests
In directory cvs.zope.org:/tmp/cvs-serv22918/tests

Modified Files:
	testScheduler.py 
Log Message:
Don't let UI fail when there is a data structure inconsistency.

Give users a way to recover from a data structure inconsistencies.

Do cleanup of old lists in times btree.


=== Products/Scheduler/tests/testScheduler.py 1.3 => 1.4 ===
--- Products/Scheduler/tests/testScheduler.py:1.3	Tue Jun  3 10:50:45 2003
+++ Products/Scheduler/tests/testScheduler.py	Mon Jul  7 17:31:53 2003
@@ -118,6 +118,37 @@
         app.portal_scheduler.schedule(now, task)
         self.assertRaises(ConflictError, self._notify)
 
+    def testTolerateInconsistentDataStructures(self):
+        app = self.app
+        then = time.time()
+        task = Task('test', then, '/put_stuff')
+        app.portal_scheduler.schedule(then, task)
+        taskid = task.taskid
+        # make the data structures inconsistent
+        del app.portal_scheduler.tasks[taskid]
+        i = app.portal_scheduler.getPendingTaskInfo()
+        desc = i[0][1]['description']
+        self.assert_(desc.startswith('Scheduler inconsistency'))
+
+    def testFixupTimesBtree(self):
+        app = self.app
+        then = time.time()
+        task1 = Task('test', then, '/put_stuff')
+        task2 = Task('test', then, '/put_stuff')
+        app.portal_scheduler.schedule(then, task1)
+        app.portal_scheduler.schedule(then, task2)
+        # make the data structures inconsistent
+        del app.portal_scheduler.tasks[task1.taskid]
+        i = app.portal_scheduler.getPendingTaskInfo()
+        self.assertEqual(len(i), 2)
+        desc = i[0][1]['description']
+        self.assert_(desc.startswith('Scheduler inconsistency'))
+        app.portal_scheduler.fixupTimesBtree()
+        i = app.portal_scheduler.getPendingTaskInfo()
+        self.assertEqual(len(i), 1)
+        desc = i[0][1]['description']
+        self.assert_(not desc.startswith('Scheduler inconsistency'))
+                     
 from AccessControl import ModuleSecurityInfo
 ModuleSecurityInfo('Products').declarePublic('Scheduler')
 ModuleSecurityInfo('Products.Scheduler').declarePublic('tests')