[Zope3-checkins] CVS: Zope3/src/zodb/tests - test_connection.py:1.3.4.2

Jeremy Hylton jeremy@zope.com
Mon, 3 Mar 2003 17:10:51 -0500


Update of /cvs-repository/Zope3/src/zodb/tests
In directory cvs.zope.org:/tmp/cvs-serv640/src/zodb/tests

Modified Files:
      Tag: jeremy-atomic-invalidation-branch
	test_connection.py 
Log Message:
Add tests of _p_independent() behavior.


=== Zope3/src/zodb/tests/test_connection.py 1.3.4.1 => 1.3.4.2 ===
--- Zope3/src/zodb/tests/test_connection.py:1.3.4.1	Sat Mar  1 21:38:00 2003
+++ Zope3/src/zodb/tests/test_connection.py	Mon Mar  3 17:10:50 2003
@@ -26,6 +26,16 @@
 class P(Persistent):
     pass
 
+class Independent(Persistent):
+
+    def _p_independent(self):
+        return True
+
+class DecoyIndependent(Persistent):
+
+    def _p_independent(self):
+        return False
+
 class ConnectionTests(IDataManagerTests):
 
     def setUp(self):
@@ -47,7 +57,7 @@
     def test_cacheGC(self):
         self.datamgr.cacheGC()
 
-    def testReadConflict(self):
+    def testReadConflict(self, shouldFail=True):
         # Two transactions run concurrently.  Each reads some object,
         # then one commits and the other tries to read an object
         # modified by the first.  This read should fail with a conflict
@@ -76,7 +86,11 @@
         # An attempt to access obj should fail, because r2 was read
         # earlier in the transaction and obj was modified by the othe
         # transaction.
-        self.assertRaises(ReadConflictError, lambda: obj.child1)
+        if shouldFail:
+            self.assertRaises(ReadConflictError, lambda: obj.child1)
+        else:
+            # make sure that accessing the object succeeds
+            obj.child1
         txn.abort()
 
     def testReadConflictIgnored(self):
@@ -129,6 +143,14 @@
 
         self.assertRaises(ConflictError, txn.commit)
         get_transaction().abort()
+
+    def testIndependent(self):
+        self.obj = Independent()
+        self.testReadConflict(shouldFail=False)
+
+    def testNotIndependent(self):
+        self.obj = DecoyIndependent()
+        self.testReadConflict()
 
     def tearDown(self):
         self.datamgr.close()