[Zope-Checkins] CVS: Zope3/src/ZODB/tests - testTransaction.py:1.19.2.1 testConnection.py:1.8.2.1 MTStorage.py:1.15.2.1

Jeremy Hylton jeremy at zope.com
Thu Mar 18 16:19:05 EST 2004


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

Modified Files:
      Tag: jeremy-txn-branch
	testTransaction.py testConnection.py MTStorage.py 
Log Message:
Commit working changes for ReviseTransactionAPI to jeremy-txn-branch.

All of the transaction tests pass except for two failures 
    testExceptionInSubAbortSub
    testExceptionInSubCommitSub


=== Zope3/src/ZODB/tests/testTransaction.py 1.19 => 1.19.2.1 ===
--- Zope3/src/ZODB/tests/testTransaction.py:1.19	Thu Feb 26 19:31:55 2004
+++ Zope3/src/ZODB/tests/testTransaction.py	Thu Mar 18 16:18:33 2004
@@ -48,11 +48,13 @@
 import unittest
 
 from ZODB import Transaction
+import transaction
 
 class TransactionTests(unittest.TestCase):
 
     def setUp(self):
 
+        transaction.manager = transaction.TransactionManager()
         Transaction.hosed = 0
         self.sub1 = DataObject()
         self.sub2 = DataObject()
@@ -60,8 +62,7 @@
         self.nosub1 = DataObject(nost=1)
 
     def tearDown(self):
-
-        Transaction.free_transaction()
+        pass
 
     # basic tests with two sub trans jars
     # really we only need one, so tests for
@@ -124,18 +125,12 @@
         assert self.sub1._p_jar.cabort_sub == 1
 
     def testMultipleSubTransactionCommitCommit(self):
-
-        # add it
         self.sub1.modify()
-
         get_transaction().commit(1)
 
-        # add another
         self.sub2.modify()
-
         # reset a flag on the original to test it again
         self.sub1.ctpc_finish = 0
-
         get_transaction().commit(1)
 
         # this is interesting.. we go through
@@ -150,7 +145,7 @@
 
         get_transaction().commit()
 
-        # we did an implicit sub commit, is this impl artifiact?
+        # we did an implicit sub commit, is this impl artifact?
         assert self.sub3._p_jar.ccommit_sub == 1
         assert self.sub1._p_jar.ctpc_finish > 1
 
@@ -413,22 +408,12 @@
     ###
 
     def testExceptionInSubCommitSub(self):
-        """
-        this tests exhibits some odd behavior,
-        nothing thats technically incorrect...
-
-        basically it seems non deterministic, even
-        stranger the behavior seems dependent on what
-        values i test after the fact... very odd,
-        almost relativistic.
-
-        in-retrospect this is from the fact that
-        dictionaries are used to store jars at some point
-
-        """
+        # It's harder than normal to verify test results, because
+        # the subtransaction jars are stored in a dictionary.  The
+        # other in which jars are processed depends on the order
+        # they come out of the dictionary.
 
         self.sub1.modify()
-
         get_transaction().commit(1)
 
         self.nosub1.modify()
@@ -442,24 +427,31 @@
 
         try:
             get_transaction().commit()
-        except TestTxnException: pass
-
+        except TestTxnException:
+            pass
 
-        # odd this doesn't seem to be entirely deterministic..
         if self.sub1._p_jar.ccommit_sub:
             assert self.sub1._p_jar.ctpc_abort == 1
         else:
             assert self.sub1._p_jar.cabort_sub == 1
 
+        assert self.sub2._p_jar.ctpc_abort == 1
+        assert self.nosub1._p_jar.ctpc_abort == 1
+
+        # XXX this test fails intermittently
         if self.sub3._p_jar.ccommit_sub:
             assert self.sub3._p_jar.ctpc_abort == 1
         else:
             assert self.sub3._p_jar.cabort_sub == 1
 
-        assert self.sub2._p_jar.ctpc_abort == 1
-        assert self.nosub1._p_jar.ctpc_abort == 1
-
     def testExceptionInSubAbortSub(self):
+        # This test has two errors.  When commit_sub() is called on
+        # sub1, it will fail.  If sub1 is handled first, it will raise
+        # an except and abort_sub() will be called on sub2.  If sub2
+        # is handled first, then commit_sub() will fail after sub2 has
+        # already begun its top-level transaction and tpc_abort() will
+        # be called.
+        
         self.sub1._p_jar = SubTransactionJar(errors='commit_sub')
         self.sub1.modify(nojar=1)
         get_transaction().commit(1)
@@ -482,7 +474,7 @@
         # called, then tpc_abort() should be called to abort the
         # actual transaction.  If not, then calling abort_sub() is
         # sufficient.
-        if self.sub3._p_jar.ccommit_sub == 1:
+        if self.sub3._p_jar.ccommit_sub:
             self.assertEqual(self.sub3._p_jar.ctpc_abort, 1)
         else:
             self.assertEqual(self.sub3._p_jar.cabort_sub, 1)
@@ -526,7 +518,7 @@
 class DataObject:
 
     def __init__(self, nost=0):
-        self.nost= nost
+        self.nost = nost
         self._p_jar = None
 
     def modify(self, nojar=0, tracing=0):
@@ -557,7 +549,12 @@
         self.ccommit_sub = 0
 
     def __repr__(self):
-        return "<jar %X %s>" % (id(self), self.errors)
+        return "<%s %X %s>" % (self.__class__.__name__, id(self), self.errors)
+
+    def sortKey(self):
+        # All these jars use the same sort key, and Python's list.sort()
+        # is stable.  These two 
+        return self.__class__.__name__
 
     def check(self, method):
         if self.tracing:


=== Zope3/src/ZODB/tests/testConnection.py 1.8 => 1.8.2.1 ===
--- Zope3/src/ZODB/tests/testConnection.py:1.8	Sat Mar 13 02:48:11 2004
+++ Zope3/src/ZODB/tests/testConnection.py	Thu Mar 18 16:18:33 2004
@@ -483,8 +483,6 @@
     appended to self._finished.
     """
 
-    sortKey = 'StubStorage sortKey'
-
     # internal
     _oid = 1
     _transaction = None
@@ -501,6 +499,9 @@
         oid = str(self._oid)
         self._oid += 1
         return oid
+
+    def sortKey(self):
+        return 'StubStorage sortKey'
 
     def tpc_begin(self, transaction):
         if transaction is None:


=== Zope3/src/ZODB/tests/MTStorage.py 1.15 => 1.15.2.1 ===
--- Zope3/src/ZODB/tests/MTStorage.py:1.15	Thu Feb 26 19:31:55 2004
+++ Zope3/src/ZODB/tests/MTStorage.py	Thu Mar 18 16:18:33 2004
@@ -59,6 +59,7 @@
 
     def runtest(self):
         conn = self.db.open()
+        conn.sync()
         root = conn.root()
         d = self.get_thread_dict(root)
         if d is None:




More information about the Zope-Checkins mailing list