[CalendarServer-changes] [11897] CalendarServer/trunk/twext/protocols/test/test_memcache.py

source_changes at macosforge.org source_changes at macosforge.org
Wed Mar 12 11:23:42 PDT 2014


Revision: 11897
          http://trac.calendarserver.org//changeset/11897
Author:   glyph at apple.com
Date:     2013-11-06 14:56:10 -0800 (Wed, 06 Nov 2013)
Log Message:
-----------
Test adjustments necessary for future version of Twisted.

Modified Paths:
--------------
    CalendarServer/trunk/twext/protocols/test/test_memcache.py

Modified: CalendarServer/trunk/twext/protocols/test/test_memcache.py
===================================================================
--- CalendarServer/trunk/twext/protocols/test/test_memcache.py	2013-11-06 22:52:10 UTC (rev 11896)
+++ CalendarServer/trunk/twext/protocols/test/test_memcache.py	2013-11-06 22:56:10 UTC (rev 11897)
@@ -14,7 +14,17 @@
 from twisted.internet.defer import Deferred, gatherResults, TimeoutError
 
 
+def onConnectionLossFire(protocol, deferred):
+    """
+    When the given L{MemCacheProtocol} is disconnected, fire the given
+    L{Deferred} with L{None}.
+    """
+    def cl(reason):
+        deferred.callback(None)
+    protocol.connectionLost = cl
 
+
+
 class MemCacheTestCase(TestCase):
     """
     Test client protocol class L{MemCacheProtocol}.
@@ -244,7 +254,7 @@
         d1 = self.proto.get("foo")
         d2 = self.proto.get("bar")
         d3 = Deferred()
-        self.proto.connectionLost = d3.callback
+        onConnectionLossFire(self.proto, d3)
 
         self.clock.advance(self.proto.persistentTimeOut)
         self.assertFailure(d1, TimeoutError)
@@ -280,7 +290,7 @@
         """
         d1 = self.proto.get("foo")
         d2 = Deferred()
-        self.proto.connectionLost = d2.callback
+        onConnectionLossFire(self.proto, d2)
 
         self.proto.dataReceived("VALUE foo 0 10\r\n12345")
         self.clock.advance(self.proto.persistentTimeOut)
@@ -295,7 +305,7 @@
         """
         d1 = self.proto.stats()
         d2 = Deferred()
-        self.proto.connectionLost = d2.callback
+        onConnectionLossFire(self.proto, d2)
 
         self.proto.dataReceived("STAT foo bar\r\n")
         self.clock.advance(self.proto.persistentTimeOut)
@@ -311,7 +321,7 @@
         d1 = self.proto.get("foo")
         d2 = self.proto.get("bar")
         d3 = Deferred()
-        self.proto.connectionLost = d3.callback
+        onConnectionLossFire(self.proto, d3)
 
         self.clock.advance(self.proto.persistentTimeOut - 1)
         self.proto.dataReceived("VALUE foo 0 3\r\nbar\r\nEND\r\n")
@@ -338,7 +348,7 @@
         """
         d1 = self.proto.get("foo")
         d3 = Deferred()
-        self.proto.connectionLost = d3.callback
+        onConnectionLossFire(self.proto, d3)
 
         self.clock.advance(self.proto.persistentTimeOut - 1)
         d2 = self.proto.get("bar")
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140312/273f3b24/attachment.html>


More information about the calendarserver-changes mailing list