[Zope-Checkins] CVS: Products/Transience/tests - testTransientObjectContainer.py:1.14.2.5

Chris McDonough chrism at plope.com
Sun Oct 10 22:40:48 EDT 2004


Update of /cvs-repository/Products/Transience/tests
In directory cvs.zope.org:/tmp/cvs-serv30889/tests

Modified Files:
      Tag: Zope-2_7-branch
	testTransientObjectContainer.py 
Log Message:
- Make TransientObjectContainer __setstate__ actually work. ;-)
  Upgrades should be flawless from Zope 2.7.0, 2.7.1, and 2.7.2.
  Upgrades from 2.6.3 will work, but data may not be retained.

- Added a "reset" button to the TOC management page and a reset
  argument to the associated target method.  This allows users
  to decide to ditch the contents of their TOC and "start over".
  It also has the effect of setting persistent objects which
  cause the logic in __setstate__ to basically be a noop after
  a single run.

- Added tests for manage_changeTOC and disabling inband gc.

- Changed default timeout for new TOCs to 60 seconds (this
  is helpful to prevent certain classes of conflicts, see
  http://www.plope.com/Members/dunny/conflicts for more info.



=== Products/Transience/tests/testTransientObjectContainer.py 1.14.2.4 => 1.14.2.5 ===
--- Products/Transience/tests/testTransientObjectContainer.py:1.14.2.4	Fri Sep 17 22:58:19 2004
+++ Products/Transience/tests/testTransientObjectContainer.py	Sun Oct 10 22:40:48 2004
@@ -396,6 +396,91 @@
         for x in range(11):
             self.t.new(str(x))
 
+    def test_manage_changeTOCWorks(self):
+        # dont reset data if only title, add notifier, del notifier or limit
+        # have changed
+        self._tocmakeone()
+        self.assertEqual(self.t.getLen(), 1)
+        self.t.manage_changeTransientObjectContainer(
+            'titlechanged', timeout_mins=self.timeout/60,
+            period_secs=self.timeout,
+            addNotification='/foochanged', delNotification='/barchanged',
+            limit=100)
+        self.assertEqual(self.t.getLen(), 1)
+        
+        # reset data implicitly if timeout or resolution change
+        self._tocmakeone()
+        self.t.manage_changeTransientObjectContainer(
+            'titlechanged', self.timeout/30, '/foochanged', '/barchanged',
+            100, self.timeout*2)
+        self.assertEqual(self.t.title, 'titlechanged')
+        self.assertEqual(self.t.getTimeoutMinutes(), self.timeout/30),
+        self.assertEqual(self.t.getAddNotificationTarget(), '/foochanged')
+        self.assertEqual(self.t.getDelNotificationTarget(), '/barchanged')
+        self.assertEqual(self.t.getSubobjectLimit(), 100)
+        self.assertEqual(self.t.getPeriodSeconds(), self.timeout*2)
+        self.assertEqual(self.t.getLen(), 0)
+        
+        # reset data explicitly if do_toc_reset is present but nothing else has
+        # changed
+        self._tocmakeone()
+        self.t.manage_changeTransientObjectContainer(
+            title='fleeb',
+            timeout_mins=self.timeout/60,
+            addNotification='/foo',
+            delNotification='/bar', limit=10, 
+            period_secs=self.timeout,
+            do_toc_reset=True)
+        self.assertEqual(self.t.getLen(), 0)
+
+    def _tocmakeone(self):
+        self.t = TransientObjectContainer('a', title='fleeb',
+                                          timeout_mins=self.timeout/60,
+                                          addNotification='/foo',
+                                          delNotification='/bar', limit=10, 
+                                          period_secs=self.timeout)
+        self.t.getPhysicalRoot = lambda t=self.t: t
+        self.t['a'] = 'b'
+
+    def testDisableInbandHousekeeping(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) * 2)
+        for x in range(110, 210):
+            self.t[x] = x
+
+        # we should have 100 current items
+        self.assertEqual(len(self.t.keys()), 100)
+
+        # and we should have 100 items in _data (_gc should have been called)
+        L = 0
+        for k,v in self.t._data.items():
+            L = L + len(v)
+        self.assertEqual(L, 100)
+
+        # reset TOC and disable inband housekeeping
+        self.t = TransientObjectContainer('sdc', timeout_mins=self.timeout/60,
+                                          period_secs=self.period)
+        self.t.disableInbandHousekeeping()
+
+        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
+
+        # we should have 100 current items
+        self.assertEqual(len(self.t.keys()), 100)
+
+        # but we should still actually have 200 items in _data because
+        # _gc was never called
+        L = 0
+        for k,v in self.t._data.items():
+            L = L + len(v)
+        self.assertEqual(L, 200)
+
 
 def lsubtract(l1, l2):
     l1=list(l1)



More information about the Zope-Checkins mailing list