[Zodb-checkins] CVS: ZODB3/ZODB/tests - testZODB.py:1.15.8.2

Tim Peters cvs-admin at zope.org
Thu Oct 23 20:45:57 EDT 2003


Update of /cvs-repository/ZODB3/ZODB/tests
In directory cvs.zope.org:/tmp/cvs-serv4702/ZODB/tests

Modified Files:
      Tag: Zope-2_7-branch
	testZODB.py 
Log Message:
Removed an unnecessary blank.

Also, inserted a secret private API for ignoring read conflicts.  Maybe
we'll admit to it someday, maybe not.


=== ZODB3/ZODB/tests/testZODB.py 1.15.8.1 => 1.15.8.2 ===
--- ZODB3/ZODB/tests/testZODB.py:1.15.8.1	Mon Sep 15 17:26:57 2003
+++ ZODB3/ZODB/tests/testZODB.py	Thu Oct 23 20:45:56 2003
@@ -258,7 +258,7 @@
         try:
             del index2[0]["a"]
         except ReadConflictError:
-            # This is the crux of the text.  Ignore the error.
+            # This is the crux of the test.  Ignore the error.
             pass
         else:
             self.fail("No conflict occurred")
@@ -272,6 +272,54 @@
         self.assert_(not index2[1]._p_changed)
 
         self.assertRaises(ConflictError, cn2.getTransaction().commit)
+        get_transaction().abort()
+
+    def checkIgnoreReadConflict(self):
+        # Test that an application that catches a read conflict and
+        # continues can not commit the transaction later.
+        root = self._db.open().root()
+        root["real_data"] = real_data = PersistentMapping()
+        root["index"] = index = PersistentMapping()
+
+        real_data["a"] = PersistentMapping({"indexed_value": 0})
+        real_data["b"] = PersistentMapping({"indexed_value": 1})
+        index[1] = PersistentMapping({"b": 1})
+        index[0] = PersistentMapping({"a": 1})
+        get_transaction().commit()
+
+        # load some objects from one connection
+        cn2 = self._db.open()
+        cn2.setLocalTransaction()
+        r2 = cn2.root()
+        real_data2 = r2["real_data"]
+        index2 = r2["index"]
+
+        real_data["b"]["indexed_value"] = 0
+        del index[1]["b"]
+        index[0]["b"] = 1
+        get_transaction().commit()
+
+        del real_data2["a"]
+        try:
+            del index2[0]["a"]
+        except ReadConflictError, obj:
+            # The point of this test is to make sure that the conflict
+            # can be ignored.
+            obj.ignore()
+        else:
+            self.fail("No conflict occurred")
+
+        # real_data2 still ready to commit
+        self.assert_(real_data2._p_changed)
+
+        # index2 values not ready to commit
+        self.assert_(not index2._p_changed)
+        self.assert_(not index2[0]._p_changed)
+        self.assert_(not index2[1]._p_changed)
+
+        # The commit should succeed despite the ReadConflictError, because
+        # we explicitly said to ignore it.
+        cn2.getTransaction().commit()
         get_transaction().abort()
 
     def checkIndependent(self):




More information about the Zodb-checkins mailing list