[Zodb-checkins] CVS: ZODB3/ZODB/tests - testConnection.py:1.1.4.2

Gintautas Miliauskas gintas at pov.lt
Tue Feb 3 14:14:43 EST 2004


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

Modified Files:
      Tag: zope3-zodb3-devel-branch
	testConnection.py 
Log Message:
Fixed the implementation of Connection.add() to not lose objects that are
created during a __getstate__ and are also added to the Connection with
add(). (Objects that were created in __getstate__ but not added with add()
were just fine!)

Added tests for this.

SteveA + Gintas


=== ZODB3/ZODB/tests/testConnection.py 1.1.4.1 => 1.1.4.2 ===
--- ZODB3/ZODB/tests/testConnection.py:1.1.4.1	Sun Feb  1 13:38:39 2004
+++ ZODB3/ZODB/tests/testConnection.py	Tue Feb  3 14:14:41 2004
@@ -108,6 +108,37 @@
         self.assertEquals(self.db._storage._stored, [oid])
         self.assertEquals(self.db._storage._finished, [oid])
 
+    def checkModifyOnGetstate(self):
+        subobj = StubObject()
+        obj = ModifyOnGetStateObject(subobj)
+        
+        self.datamgr.tpc_begin(self.transaction)
+        self.datamgr.commit(obj, self.transaction)
+        self.datamgr.tpc_finish(self.transaction)
+        storage = self.db._storage
+        self.assert_(obj._p_oid in storage._stored, "object was not stored")
+        self.assert_(subobj._p_oid in storage._stored,
+                "subobject was not stored")
+        self.assert_(self.datamgr._added_during_commit is None)
+
+    def checkErrorDuringCommit(self):
+        # We need to check that _added_during_commit still gets set to None
+        # when there is an error during commit()/
+        obj = ErrorOnGetstateObject()
+        
+        self.datamgr.tpc_begin(self.transaction)
+        self.assertRaises(ErrorOnGetstateException,
+                self.datamgr.commit, obj, self.transaction)
+        self.assert_(self.datamgr._added_during_commit is None)
+
+    def checkUnusedAddWorks(self):
+        # When an object is added, but not committed, it shouldn't be stored,
+        # but also it should be an error.
+        obj = StubObject()
+        self.datamgr.add(obj)
+        self.datamgr.tpc_begin(self.transaction)
+        self.datamgr.tpc_finish(self.transaction)
+        self.assert_(obj._p_oid not in self.datamgr._storage._stored)
 
 # ---- stubs
 
@@ -117,6 +148,24 @@
 
 class StubTransaction:
     pass
+
+class ErrorOnGetstateException(Exception):
+    pass
+    
+class ErrorOnGetstateObject(Persistent):
+
+    def __getstate__(self):
+        raise ErrorOnGetstateException
+
+class ModifyOnGetStateObject(Persistent):
+
+    def __init__(self, p):
+        self._v_p = p
+
+    def __getstate__(self):
+        self._p_jar.add(self._v_p)
+        self.p = self._v_p
+        return Persistent.__getstate__(self)
 
 
 class StubStorage:




More information about the Zodb-checkins mailing list