[Zodb-checkins] CVS: Packages/ZODB/tests - testCache.py:1.13.10.8

Tim Peters tim.one at comcast.net
Thu Feb 24 14:59:04 EST 2005


Update of /cvs-repository/Packages/ZODB/tests
In directory cvs.zope.org:/tmp/cvs-serv25842/ZODB/tests

Modified Files:
      Tag: Zope-2_7-branch
	testCache.py 
Log Message:
Change the exception raised when an attempt is made to add two objects to
the cache with the same oid.  The former messsage didn't make sense.

Add a test to verify that this exception does get raised, and that the
message given is the intended one.

This is the first of a series of checkins, to fix critical bugs where
ZODB can in fact raise this exception in rare, but normal, use cases.


=== Packages/ZODB/tests/testCache.py 1.13.10.7 => 1.13.10.8 ===
--- Packages/ZODB/tests/testCache.py:1.13.10.7	Mon Jun  7 18:46:47 2004
+++ Packages/ZODB/tests/testCache.py	Thu Feb 24 14:59:04 2005
@@ -369,6 +369,28 @@
         else:
             self.fail("expect that you can't delete jar of cached object")
 
+    def checkTwoObjsSameOid(self):
+        # Try to add two distinct objects with the same oid to the cache.
+        # This has always been an error, but the error message prior to
+        # ZODB 3.2.6 didn't make sense.  This test verifies that (a) an
+        # exception is raised; and, (b) the error message is the intended
+        # one.
+        obj1 = StubObject()
+        key = obj1._p_oid = p64(1)
+        obj1._p_jar = self.jar
+        self.cache[key] = obj1
+
+        obj2 = StubObject()
+        obj2._p_oid = key
+        obj2._p_jar = self.jar
+        try:
+            self.cache[key] = obj2
+        except ValueError, detail:
+            self.assertEqual(str(detail),
+                             "A different object already has the same oid")
+        else:
+            self.fail("two objects with the same oid should have failed")
+
 def test_suite():
     s = unittest.makeSuite(DBMethods, 'check')
     s.addTest(unittest.makeSuite(LRUCacheTests, 'check'))



More information about the Zodb-checkins mailing list