[Zodb-checkins] CVS: Packages/ZODB/tests - testZODB.py:1.15.8.5
Tim Peters
tim.one at comcast.net
Fri Aug 27 15:03:43 EDT 2004
Update of /cvs-repository/Packages/ZODB/tests
In directory cvs.zope.org:/tmp/cvs-serv16182/lib/python/ZODB/tests
Modified Files:
Tag: Zope-2_7-branch
testZODB.py
Log Message:
New ConnectionStateError raised if an attempt to close a Connection occurs
while a transaction involving that Connection has pending changes.
Collector #789 is a starting point for rationale (short course:
POSKeyErrors, both temporary and permanent, can result otherwise).
The ZODB3 NEWS file will contain more info.
=== Packages/ZODB/tests/testZODB.py 1.15.8.4 => 1.15.8.5 ===
--- Packages/ZODB/tests/testZODB.py:1.15.8.4 Wed Aug 25 15:17:30 2004
+++ Packages/ZODB/tests/testZODB.py Fri Aug 27 15:03:43 2004
@@ -18,6 +18,7 @@
import ZODB.FileStorage
from ZODB.PersistentMapping import PersistentMapping
from ZODB.POSException import ReadConflictError, ConflictError
+from ZODB.POSException import ConnectionStateError
from ZODB.tests.StorageTestBase import removefs
from Persistence import Persistent
@@ -362,6 +363,62 @@
self.assertRaises(KeyError, rt.__getitem__, 'a')
self.assertRaises(KeyError, rt.__getitem__, 'b')
+ cn.close()
+
+ def checkCloseWithPendingChanges(self):
+ # Ensure Connection.close() w/ pending changes complains.
+
+ # Just opening and closing is fine.
+ cn = self._db.open()
+ cn.close()
+
+ # Opening, making a change, committing, and closing is fine.
+ cn = self._db.open()
+ cn.root()['a'] = 1
+ get_transaction().commit()
+ cn.close()
+
+ # Opening, making a change, and aborting is fine.
+ cn = self._db.open()
+ cn.root()['a'] = 1
+ get_transaction().abort()
+ cn.close()
+
+ # But trying to close with a change pending complains.
+ cn = self._db.open()
+ cn.root()['a'] = 10
+ self.assertRaises(ConnectionStateError, cn.close)
+
+ # This leaves the connection as it was, so we can still commit
+ # the change.
+ get_transaction().commit()
+ cn2 = self._db.open()
+ self.assertEqual(cn2.root()['a'], 10)
+ cn.close()
+ cn2.close()
+
+ # When the only changes pending are in a subtransaction, different
+ # Connection code is required to detect the problem.
+ cn = self._db.open()
+ cn.root()['a'] = 100
+ get_transaction().commit(True)
+ self.assertRaises(ConnectionStateError, cn.close)
+
+ # Again this leaves the connection as it was.
+ get_transaction().commit()
+ cn2 = self._db.open()
+ self.assertEqual(cn2.root()['a'], 100)
+ cn.close()
+ cn2.close()
+
+ # Make sure we can still close a connection after aborting a pending
+ # subtransaction.
+ cn = self._db.open()
+ cn.root()['a'] = 1000
+ get_transaction().commit(True)
+ self.assertEqual(cn.root()['a'], 1000)
+ get_transaction().abort()
+ self.assertEqual(cn.root()['a'], 100)
cn.close()
def test_suite():
More information about the Zodb-checkins
mailing list