[CalendarServer-changes] [10252] CalendarServer/branches/users/glyph/queue-locking-and-timing

source_changes at macosforge.org source_changes at macosforge.org
Fri Jan 4 16:39:11 PST 2013


Revision: 10252
          http://trac.calendarserver.org//changeset/10252
Author:   glyph at apple.com
Date:     2013-01-04 16:39:11 -0800 (Fri, 04 Jan 2013)
Log Message:
-----------
Test for failed pre-commit.

Modified Paths:
--------------
    CalendarServer/branches/users/glyph/queue-locking-and-timing/twext/enterprise/test/test_adbapi2.py

Property Changed:
----------------
    CalendarServer/branches/users/glyph/queue-locking-and-timing/

Modified: CalendarServer/branches/users/glyph/queue-locking-and-timing/twext/enterprise/test/test_adbapi2.py
===================================================================
--- CalendarServer/branches/users/glyph/queue-locking-and-timing/twext/enterprise/test/test_adbapi2.py	2013-01-05 00:39:10 UTC (rev 10251)
+++ CalendarServer/branches/users/glyph/queue-locking-and-timing/twext/enterprise/test/test_adbapi2.py	2013-01-05 00:39:11 UTC (rev 10252)
@@ -30,7 +30,7 @@
 from twisted.trial.unittest import TestCase
 
 from twisted.internet.task import Clock
-from twisted.internet.defer import Deferred
+from twisted.internet.defer import Deferred, fail
 
 from twisted.internet.interfaces import IReactorThreads
 
@@ -73,11 +73,24 @@
     """
 
     def assertResultList(self, resultList, expected):
+        """
+        Assert that a list created with L{resultOf} contais the expected
+        result.
+
+        @param resultList: The return value of L{resultOf}.
+        @type resultList: L{list}
+
+        @param expected: The expected value that should be present in the list;
+            a L{Failure} if an exception is expected to be raised.
+        """
         if not resultList:
             self.fail("No result; Deferred didn't fire yet.")
         else:
             if isinstance(resultList[0], Failure):
-                resultList[0].raiseException()
+                if isinstance(expected, Failure):
+                    resultList[0].trap(expected.type)
+                else:
+                    resultList[0].raiseException()
             else:
                 self.assertEqual(resultList, [expected])
 
@@ -1122,11 +1135,46 @@
         self.assertEquals(wait.sqlResult, None)
         self.assertEquals(result, [])
         d.callback(None)
+        # allow network I/O for pooled / networked implementation; there should
+        # be the commit message now.
         self.flushHolders()
         self.assertEquals(len(result), 1)
         self.assertEquals(wait.sqlResult, [[1, "some test sql"]])
 
 
+    def test_failPreCommit(self):
+        """
+        If callables passed to L{IAsyncTransaction.preCommit} raise an
+        exception or return a Failure, subsequent callables will not be run,
+        and the transaction will be aborted.
+        """
+        def test(flawedCallable, exc):
+            # Set up.
+            test.committed = False
+            test.aborted = False
+            # Create transaction and add monitoring hooks.
+            txn = self.createTransaction()
+            def didCommit():
+                test.committed = True
+            def didAbort():
+                test.aborted = True
+            txn.postCommit(didCommit)
+            txn.postAbort(didAbort)
+            txn.preCommit(flawedCallable)
+            result = self.resultOf(txn.commit())
+            self.flushHolders()
+            self.assertResultList(result, Failure(exc()))
+            self.assertEquals(test.aborted, True)
+            self.assertEquals(test.committed, False)
+
+        def failer():
+            return fail(ZeroDivisionError())
+        def raiser():
+            raise EOFError()
+        test(failer, ZeroDivisionError)
+        test(raiser, EOFError)
+
+
     def test_noOpCommitDoesntHinderReconnection(self):
         """
         Until you've executed a query or performed a statement on an ADBAPI
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20130104/7de8bf1f/attachment-0001.html>


More information about the calendarserver-changes mailing list