Log message for revision 111814:
  Cleaned up and speed up Transience tests a bit. Now they take 20 seconds out 
of 50 seconds total for Zope2 - before it was 30 out of 60. There should still 
be some more room for improvement.
  

Changed:
  U   Zope/trunk/src/Products/Transience/tests/fauxtime.py
  A   Zope/trunk/src/Products/Transience/tests/slowfauxtime.py
  U   Zope/trunk/src/Products/Transience/tests/testTimeoutRelated.py
  U   Zope/trunk/src/Products/Transience/tests/testTransactionHelper.py
  U   Zope/trunk/src/Products/Transience/tests/testTransientObject.py
  U   Zope/trunk/src/Products/Transience/tests/testTransientObjectContainer.py

-=-
Modified: Zope/trunk/src/Products/Transience/tests/fauxtime.py
===================================================================
--- Zope/trunk/src/Products/Transience/tests/fauxtime.py        2010-04-30 
23:00:54 UTC (rev 111813)
+++ Zope/trunk/src/Products/Transience/tests/fauxtime.py        2010-04-30 
23:53:33 UTC (rev 111814)
@@ -1,3 +1,4 @@
+import sys
 import time as origtime
 
 epoch = origtime.time()
@@ -2,8 +3,16 @@
 
+resolution = 120.0
+timeout = 30
+
+if sys.platform[:3].lower() == "win":
+    resolution = 60.0
+    timeout = 60
+
+
 def time():
-    """ False timer -- returns time 60 x faster than normal time """
-    return (origtime.time() - epoch) * 60.0
+    """ False timer -- returns time R x faster than normal time """
+    return (origtime.time() - epoch) * resolution
 
 def sleep(duration):
-    """ False sleep -- sleep for 1/60 the time specifed """
-    origtime.sleep(duration / 60.0)
+    """ False sleep -- sleep for 1/R the time specifed """
+    origtime.sleep(duration / resolution)

Added: Zope/trunk/src/Products/Transience/tests/slowfauxtime.py
===================================================================
--- Zope/trunk/src/Products/Transience/tests/slowfauxtime.py                    
        (rev 0)
+++ Zope/trunk/src/Products/Transience/tests/slowfauxtime.py    2010-04-30 
23:53:33 UTC (rev 111814)
@@ -0,0 +1,12 @@
+import time as origtime
+
+epoch = origtime.time()
+
+
+def time():
+    """ False timer -- returns time 60 x faster than normal time """
+    return (origtime.time() - epoch) * 60
+
+def sleep(duration):
+    """ False sleep -- sleep for 1/60 the time specifed """
+    origtime.sleep(duration / 60)


Property changes on: Zope/trunk/src/Products/Transience/tests/slowfauxtime.py
___________________________________________________________________
Added: svn:eol-style
   + native

Modified: Zope/trunk/src/Products/Transience/tests/testTimeoutRelated.py
===================================================================
--- Zope/trunk/src/Products/Transience/tests/testTimeoutRelated.py      
2010-04-30 23:00:54 UTC (rev 111813)
+++ Zope/trunk/src/Products/Transience/tests/testTimeoutRelated.py      
2010-04-30 23:53:33 UTC (rev 111814)
@@ -1,24 +1,12 @@
-import sys, os, time, unittest
-
-if __name__=='__main__':
-    sys.path.insert(0, '..')
-    sys.path.insert(0, '../../..')
-
 import ZODB # in order to get Persistence.Persistent working
 import transaction
 from Testing import makerequest
-import Acquisition
-from Acquisition import aq_base
 from Products.Transience.Transience import TransientObjectContainer
 import Products.Transience.Transience
 import Products.Transience.TransientObject
-from Products.PythonScripts.PythonScript import PythonScript
-from ZODB.POSException import InvalidObjectReference
-from DateTime import DateTime
-from unittest import TestCase, TestSuite, TextTestRunner, makeSuite
+from unittest import TestCase, TestSuite, makeSuite
 from ZODB.DemoStorage import DemoStorage
 from OFS.Application import Application
-import  threading
 import fauxtime
 import time as oldtime
 
@@ -26,7 +14,6 @@
 stuff = {}
 
 def _getApp():
-
     app = stuff.get('app', None)
     if not app:
         ds = DemoStorage()
@@ -109,10 +96,9 @@
     def testDelNotification(self):
         self.app.sm.setDelNotificationTarget(delNotificationTarget)
         sdo = self.app.sm.new_or_existing('TempObject')
-        timeout = self.timeout * 60
-        # sleep 2X longer than timeout?  doesnt work at 1.1X, 1.5X?
-        fauxtime.sleep(timeout * 2) 
-        sdo1 = self.app.sm.get('TempObject')
+        # sleep longer than timeout
+        fauxtime.sleep(self.timeout * 100.0)
+        self.app.sm.get('TempObject')
         now = fauxtime.time()
         k = sdo.get('endtime')
         self.assertEqual(type(k), type(now))
@@ -122,18 +108,17 @@
         # in response to http://zope.org/Collectors/Zope/1403
         self.assertEqual(None, self.app.sm._getCallback('/foo/bar/baz'))
 
+
 def addNotificationTarget(item, context):
     item['starttime'] = fauxtime.time()
 
+
 def delNotificationTarget(item, context):
     item['endtime'] = fauxtime.time()
 
+
 def test_suite():
     last_accessed = makeSuite(TestLastAccessed, 'test')
     start_end = makeSuite(TestNotifications, 'test')
     suite = TestSuite((start_end, last_accessed))
     return suite
-
-if __name__ == '__main__':
-    runner = TextTestRunner(verbosity=9)
-    runner.run(test_suite())

Modified: Zope/trunk/src/Products/Transience/tests/testTransactionHelper.py
===================================================================
--- Zope/trunk/src/Products/Transience/tests/testTransactionHelper.py   
2010-04-30 23:00:54 UTC (rev 111813)
+++ Zope/trunk/src/Products/Transience/tests/testTransactionHelper.py   
2010-04-30 23:53:33 UTC (rev 111814)
@@ -10,17 +10,13 @@
 # FOR A PARTICULAR PURPOSE
 #
 ##############################################################################
-import sys, os, time, random, unittest
 
-if __name__ == "__main__":
-    sys.path.insert(0, '../../..')
-
-import ZODB
 import transaction
-from unittest import TestCase, TestSuite, TextTestRunner, makeSuite
+from unittest import TestCase, makeSuite
 from Products.Transience.TransactionHelper import PreventTransactionCommit, \
          makeTransactionUncommittable
 
+
 class TestTransactionHelper(TestCase):
     def setUp(self):
         self.t = transaction.get()
@@ -32,11 +28,8 @@
         makeTransactionUncommittable(self.t, "test")
         self.assertRaises(PreventTransactionCommit, transaction.commit)
         transaction.abort()
-        
+
+
 def test_suite():
     suite = makeSuite(TestTransactionHelper, 'test')
     return suite
-
-if __name__ == '__main__':
-    runner = TextTestRunner(verbosity=9)
-    runner.run(test_suite())

Modified: Zope/trunk/src/Products/Transience/tests/testTransientObject.py
===================================================================
--- Zope/trunk/src/Products/Transience/tests/testTransientObject.py     
2010-04-30 23:00:54 UTC (rev 111813)
+++ Zope/trunk/src/Products/Transience/tests/testTransientObject.py     
2010-04-30 23:53:33 UTC (rev 111814)
@@ -10,14 +10,11 @@
 # FOR A PARTICULAR PURPOSE
 #
 ##############################################################################
-import sys, os, unittest
 
-import ZODB
 from Products.Transience.Transience import TransientObjectContainer
-from Products.Transience.TransientObject import TransientObject
 import Products.Transience.TransientObject
 import Products.Transience.Transience
-from unittest import TestCase, TestSuite, TextTestRunner, makeSuite
+from unittest import TestCase, TestSuite, makeSuite
 import time as oldtime
 import fauxtime
 
@@ -27,7 +24,7 @@
         Products.Transience.TransientObject.time = fauxtime
         Products.Transience.Transience.setStrict(1)
         self.errmargin = .20
-        self.timeout = 60
+        self.timeout = fauxtime.timeout
         self.t = TransientObjectContainer('sdc', timeout_mins=self.timeout/60)
 
     def tearDown(self):
@@ -69,7 +66,6 @@
 
     def testSetLastModified(self):
         t = self.t.new('xyzzy')
-        ft = fauxtime.time()
         t.setLastModified()
         self.failIfEqual(t.getLastModified(), None)
 
@@ -137,7 +133,3 @@
     'epoch': 999999999,
     'fauxtime': fauxtime
     }
-
-if __name__ == '__main__':
-    runner = TextTestRunner(verbosity=9)
-    runner.run(test_suite())

Modified: 
Zope/trunk/src/Products/Transience/tests/testTransientObjectContainer.py
===================================================================
--- Zope/trunk/src/Products/Transience/tests/testTransientObjectContainer.py    
2010-04-30 23:00:54 UTC (rev 111813)
+++ Zope/trunk/src/Products/Transience/tests/testTransientObjectContainer.py    
2010-04-30 23:53:33 UTC (rev 111814)
@@ -10,30 +10,28 @@
 # FOR A PARTICULAR PURPOSE
 #
 ##############################################################################
-import sys, os, time, random, unittest
+import random
 
-if __name__ == "__main__":
-    sys.path.insert(0, '../../..')
-
-import ZODB
 from Products.Transience.Transience import TransientObjectContainer,\
-     MaxTransientObjectsExceeded, SPARE_BUCKETS, getCurrentTimeslice
+     MaxTransientObjectsExceeded, SPARE_BUCKETS
 from Products.Transience.TransientObject import TransientObject
 import Products.Transience.Transience
 import Products.Transience.TransientObject
-from ExtensionClass import Base
-from unittest import TestCase, TestSuite, TextTestRunner, makeSuite
+from unittest import TestCase, TestSuite, makeSuite
 import time as oldtime
 import fauxtime
+import slowfauxtime
 
-class TestBase(TestCase):
+
+class TestTransientObjectContainer(TestCase):
+
     def setUp(self):
         Products.Transience.Transience.time = fauxtime
         Products.Transience.TransientObject.time = fauxtime
         Products.Transience.Transience.setStrict(1)
-                                          
+
         self.errmargin = .20
-        self.timeout = 120
+        self.timeout = fauxtime.timeout
         self.period = 20
         self.t = TransientObjectContainer('sdc', timeout_mins=self.timeout/60,
                                           period_secs=self.period)
@@ -44,7 +42,6 @@
         Products.Transience.TransientObject.time = oldtime
         Products.Transience.Transience.setStrict(0)
 
-class TestTransientObjectContainer(TestBase):
     def testGetItemFails(self):
         self.assertRaises(KeyError, self._getitemfail)
 
@@ -239,59 +236,6 @@
             except KeyError:
                 self.failIf(self.t.has_key(x))
 
-    def testItemsGetExpired(self):
-        for x in range(10, 110):
-            self.t[x] = x
-        # these items will time out while we sleep
-        fauxtime.sleep(self.timeout * (self.errmargin+1))
-        for x in range(110, 210):
-            self.t[x] = x
-        self.assertEqual(len(self.t.keys()), 100)
-
-        # call _gc just to make sure __len__ gets changed after a gc
-        #self.t._gc()
-        self.assertEqual(len(self.t), 100)
-
-        # we should still have 100 - 199
-        for x in range(110, 210):
-            self.assertEqual(self.t[x], x)
-        # but we shouldn't have 0 - 100
-        for x in range(10, 110):
-            try: self.t[x]
-            except KeyError: pass
-            else: assert 1 == 2, x
-
-    def testChangingTimeoutWorks(self):
-        # 1 minute
-        for x in range(10, 110):
-            self.t[x] = x
-        fauxtime.sleep(self.timeout * (self.errmargin+1))
-        self.assertEqual(len(self.t.keys()), 0)
-
-        # 2 minutes
-        self.t._setTimeout(self.timeout/60*2, self.period)
-        self.t._reset()
-        for x in range(10, 110):
-            self.t[x] = x
-        fauxtime.sleep(self.timeout)
-
-
-        self.assertEqual(len(self.t.keys()), 100)
-        fauxtime.sleep(self.timeout * (self.errmargin+1))
-        self.assertEqual(len(self.t.keys()), 0)
-
-        # 3 minutes
-        self.t._setTimeout(self.timeout/60*3, self.period)
-        self.t._reset()
-        for x in range(10, 110):
-            self.t[x] = x
-        fauxtime.sleep(self.timeout)
-        self.assertEqual(len(self.t.keys()), 100)
-        fauxtime.sleep(self.timeout)
-        self.assertEqual(len(self.t.keys()), 100)
-        fauxtime.sleep(self.timeout * (self.errmargin+1))
-        self.assertEqual(len(self.t.keys()), 0)
-
     def testGetDelaysTimeout(self):
         for x in range(10, 110):
             self.t[x] = x
@@ -352,10 +296,10 @@
         self.failUnless(issubclass(t.__class__, TransientObject))
 
     def _dupNewItem(self):
-        t = self.t.new('foobieblech')
+        self.t.new('foobieblech')
 
     def test_newDupFails(self):
-        t = self.t.new('foobieblech')
+        self.t.new('foobieblech')
         self.assertRaises(KeyError, self._dupNewItem)
 
     def test_new_or_existing(self):
@@ -397,6 +341,79 @@
             self.t.new(str(x))
 
 
+class TestSlowTransientObjectContainer(TestCase):
+
+    def setUp(self):
+        Products.Transience.Transience.time = slowfauxtime
+        Products.Transience.TransientObject.time = slowfauxtime
+        Products.Transience.Transience.setStrict(1)
+
+        self.errmargin = .20
+        self.timeout = 120
+        self.period = 20
+        self.t = TransientObjectContainer('sdc', timeout_mins=self.timeout/60,
+                                          period_secs=self.period)
+
+    def tearDown(self):
+        self.t = None
+        Products.Transience.Transience.time = oldtime
+        Products.Transience.TransientObject.time = oldtime
+        Products.Transience.Transience.setStrict(0)
+
+    def testChangingTimeoutWorks(self):
+        # TODO: This test is slooooow
+        # 1 minute
+        for x in range(10, 110):
+            self.t[x] = x
+        slowfauxtime.sleep(self.timeout * (self.errmargin + 1))
+        self.assertEqual(len(self.t.keys()), 0)
+
+        # 2 minutes
+        self.t._setTimeout(self.timeout/60*2, self.period)
+        self.t._reset()
+        for x in range(10, 110):
+            self.t[x] = x
+        slowfauxtime.sleep(self.timeout)
+
+        self.assertEqual(len(self.t.keys()), 100)
+        slowfauxtime.sleep(self.timeout * (self.errmargin+1))
+        self.assertEqual(len(self.t.keys()), 0)
+
+        # 3 minutes
+        self.t._setTimeout(self.timeout/60*3, self.period)
+        self.t._reset()
+        for x in range(10, 110):
+            self.t[x] = x
+        slowfauxtime.sleep(self.timeout)
+        self.assertEqual(len(self.t.keys()), 100)
+        slowfauxtime.sleep(self.timeout)
+        self.assertEqual(len(self.t.keys()), 100)
+        slowfauxtime.sleep(self.timeout * (self.errmargin+1))
+        self.assertEqual(len(self.t.keys()), 0)
+
+    def testItemsGetExpired(self):
+        for x in range(10, 110):
+            self.t[x] = x
+        # these items will time out while we sleep
+        slowfauxtime.sleep(self.timeout * (self.errmargin+1))
+        for x in range(110, 210):
+            self.t[x] = x
+        self.assertEqual(len(self.t.keys()), 100)
+
+        # call _gc just to make sure __len__ gets changed after a gc
+        #self.t._gc()
+        self.assertEqual(len(self.t), 100)
+
+        # we should still have 100 - 199
+        for x in range(110, 210):
+            self.assertEqual(self.t[x], x)
+        # but we shouldn't have 0 - 100
+        for x in range(10, 110):
+            try: self.t[x]
+            except KeyError: pass
+            else: assert 1 == 2, x
+
+
 def lsubtract(l1, l2):
     l1=list(l1)
     l2=list(l2)
@@ -404,11 +421,9 @@
     l = l + filter(lambda x, l2=l2: x not in l2, l1)
     return l
 
+
 def test_suite():
-    testsuite = makeSuite(TestTransientObjectContainer, 'test')
-    alltests = TestSuite((testsuite,))
-    return alltests
-
-if __name__ == '__main__':
-    runner = TextTestRunner(verbosity=9)
-    runner.run(test_suite())
+    suite = TestSuite()
+    suite.addTest(makeSuite(TestTransientObjectContainer))
+    suite.addTest(makeSuite(TestSlowTransientObjectContainer))
+    return suite

_______________________________________________
Zope-Checkins maillist  -  Zope-Checkins@zope.org
https://mail.zope.org/mailman/listinfo/zope-checkins

Reply via email to