[CalendarServer-changes] [11886] CalendarServer/branches/users/glyph/whenNotProposed/twext/ enterprise/test/test_queue.py

source_changes at macosforge.org source_changes at macosforge.org
Wed Mar 12 11:20:26 PDT 2014


Revision: 11886
          http://trac.calendarserver.org//changeset/11886
Author:   glyph at apple.com
Date:     2013-11-04 12:07:31 -0800 (Mon, 04 Nov 2013)
Log Message:
-----------
Test for failure case.

Modified Paths:
--------------
    CalendarServer/branches/users/glyph/whenNotProposed/twext/enterprise/test/test_queue.py

Modified: CalendarServer/branches/users/glyph/whenNotProposed/twext/enterprise/test/test_queue.py
===================================================================
--- CalendarServer/branches/users/glyph/whenNotProposed/twext/enterprise/test/test_queue.py	2013-11-04 20:07:31 UTC (rev 11885)
+++ CalendarServer/branches/users/glyph/whenNotProposed/twext/enterprise/test/test_queue.py	2013-11-04 20:07:31 UTC (rev 11886)
@@ -36,6 +36,7 @@
 )
 
 from twisted.trial.unittest import TestCase
+from twisted.python.failure import Failure
 from twisted.internet.defer import (
     Deferred, inlineCallbacks, gatherResults, passthru#, returnValue
 )
@@ -282,7 +283,7 @@
         cph = ConnectionPoolHelper()
         cph.setUp(test=self)
         cph.pauseHolders()
-        lq = LocalQueuer(cph.createTransaction())
+        lq = LocalQueuer(cph.createTransaction)
         enqTxn = cph.createTransaction()
         wp = lq.enqueueWork(enqTxn, DummyWorkItem, a=3, b=4)
         d = wp.whenProposed()
@@ -292,7 +293,29 @@
         self.assertEquals(len(r), 1)
 
 
+    def test_whenProposedFailure(self):
+        """
+        The L{Deferred} returned by L{WorkProposal.whenProposed} fails with an
+        errback when the SQL executed to create the WorkItem row fails.
+        """
+        cph = ConnectionPoolHelper()
+        cph.setUp(self)
+        cph.pauseHolders()
+        cph.factory.willConnect().executeWillFail(
+            lambda: RuntimeError("execute fail")
+        )
+        lq = LocalQueuer(cph.createTransaction)
+        enqTxn = cph.createTransaction()
+        wp = lq.enqueueWork(enqTxn, DummyWorkItem, a=3, b=4)
+        d = wp.whenProposed()
+        r = cph.resultOf(d)
+        self.assertEquals(r, [])
+        cph.flushHolders()
+        self.assertEquals(len(r), 1)
+        self.assertIsInstance(r[0], Failure)
 
+
+
 class PeerConnectionPoolUnitTests(TestCase):
     """
     L{PeerConnectionPool} has many internal components.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140312/fddf5755/attachment.html>


More information about the calendarserver-changes mailing list