[Zodb-checkins] CVS: ZODB4/src/zodb/zeo/tests - test_cache.py:1.5

Jeremy Hylton jeremy at zope.com
Fri Jun 20 14:53:46 EDT 2003


Update of /cvs-repository/ZODB4/src/zodb/zeo/tests
In directory cvs.zope.org:/tmp/cvs-serv10021/tests

Modified Files:
	test_cache.py 
Log Message:
Fix bug in load() corner case and add test case.


=== ZODB4/src/zodb/zeo/tests/test_cache.py 1.4 => 1.5 ===
--- ZODB4/src/zodb/zeo/tests/test_cache.py:1.4	Thu Jun 19 17:41:07 2003
+++ ZODB4/src/zodb/zeo/tests/test_cache.py	Fri Jun 20 13:53:45 2003
@@ -31,14 +31,16 @@
     _oid3 = 'cdefghij'
 
     def setUp(self):
-        unittest.TestCase.setUp(self)
         self.cachesize = 10*1000*1000
         self.cache = ClientCache(size=self.cachesize)
         self.cache.open()
 
     def tearDown(self):
         self.cache.close()
-        unittest.TestCase.tearDown(self)
+        for i in 0, 1:
+            path = "c1--%d.zec" % i
+            if os.path.exists(path):
+                os.remove(path)
 
     def testOpenClose(self):
         pass # All the work is done by setUp() / tearDown()
@@ -263,6 +265,42 @@
         self.failUnless(cache.getLastTid() is None)
         cache.checkSize(10*self.cachesize) # Force a file flip
         self.failUnless(cache.getLastTid() is None)
+
+    def testLoadNonversionWithVersionInFlippedCache(self):
+        # This test provokes an error seen once in an unrelated test.
+        # The object is stored in the old cache file with version data,
+        # a load for non-version data occurs.  The attempt to copy the
+        # non-version data to the new file fails.
+        nvdata = "Mend your speech a little, lest it may mar your fortunes."
+        nvserial = "12345678"
+        version = "folio"
+        vdata = "Mend your speech a little, lest you may mar your fortunes."
+        vserial = "12346789"
+        
+        self.cache.store(self._oid, nvdata, nvserial, version, vdata, vserial)
+        self.cache.checkSize(10 * self.cachesize) # force a cache flip
+
+        for i in 1, 2: # check the we can load before and after copying
+            for xversion, xdata, xserial in [("", nvdata, nvserial),
+                                          (version, vdata, vserial)]:
+                data, serial = self.cache.load(self._oid, xversion)
+                self.assertEqual(data, xdata)
+                self.assertEqual(serial, xserial)
+
+        # now cause two more cache flips and make sure the data is still there
+        self.cache.store(self._oid2, "", "", "foo", "bar", "23456789")
+        self.cache.checkSize(10 * self.cachesize) # force a cache flip
+        self.cache.load(self._oid, "")
+        self.cache.store(self._oid3, "bar", "34567890", "", "", "")
+        self.cache.checkSize(10 * self.cachesize) # force a cache flip
+        self.cache.load(self._oid, "")
+
+        for i in 1, 2: # check the we can load before and after copying
+            for xversion, xdata, xserial in [("", nvdata, nvserial),
+                                          (version, vdata, vserial)]:
+                data, serial = self.cache.load(self._oid, xversion)
+                self.assertEqual(data, xdata)
+                self.assertEqual(serial, xserial)
 
 class PersistentClientCacheTests(unittest.TestCase):
 




More information about the Zodb-checkins mailing list