Changeset 53:fd2b3f70b221 in ralphm-patches for request-tracking.patch


Ignore:
Timestamp:
Aug 3, 2011, 9:48:58 AM (11 years ago)
Author:
Ralph Meijer <ralphm@…>
Branch:
default
Message:

Small cleanups for request handling.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • request-tracking.patch

    r47 r53  
    11# HG changeset patch
    2 # Parent 60dcf9e2441bb510f1da17e6bc4401ef7b6db0e9
     2# Parent 6f36a7f92973d3843a42b4c80791715e694b66a3
    33Add iq request (set/get) tracking for StreamManager.
    44
     
    2020    from the moment request is sent over the wire.
    2121
    22 diff -r 60dcf9e2441b wokkel/subprotocols.py
    23 --- a/wokkel/subprotocols.py    Mon Feb 28 21:04:37 2011 +0100
    24 +++ b/wokkel/subprotocols.py    Fri Mar 04 09:45:24 2011 +0100
     22diff -r 6f36a7f92973 wokkel/subprotocols.py
     23--- a/wokkel/subprotocols.py    Thu Jul 28 20:14:02 2011 +0200
     24+++ b/wokkel/subprotocols.py    Wed Aug 03 09:45:01 2011 +0200
    2525@@ -156,11 +156,23 @@
    2626     @type _initialized: C{bool}
     
    7373         for p in self._packetQueue:
    7474             xs.send(p)
    75 @@ -268,6 +291,34 @@
     75@@ -268,6 +291,31 @@
    7676         for e in list(self):
    7777             e.connectionLost(reason)
     
    9090+        Handle iq response by firing associated deferred.
    9191+        """
    92 +        if getattr(iq, 'handled', False):
    93 +            return
    94 +
    9592+        try:
    9693+            d = self._iqDeferreds[iq["id"]]
     
    108105     def send(self, obj):
    109106         """
    110 @@ -285,6 +336,68 @@
     107@@ -285,6 +333,68 @@
    111108             self._packetQueue.append(obj)
    112109 
     
    141138+        if (request.stanzaKind != 'iq' or
    142139+            request.stanzaType not in ('get', 'set')):
    143 +            return defer.fail(Exception("Not a request"))
     140+            return defer.fail(ValueError("Not a request"))
    144141+
    145142+        element = request.toElement()
     
    154151+        self._iqDeferreds[element['id']] = d
    155152+
    156 +        timeout = request.timeout or self.timeout
     153+        timeout = getattr(request, 'timeout', self.timeout)
    157154+
    158155+        if timeout is not None:
     
    177174 class IQHandlerMixin(object):
    178175     """
    179 diff -r 60dcf9e2441b wokkel/test/test_subprotocols.py
    180 --- a/wokkel/test/test_subprotocols.py  Mon Feb 28 21:04:37 2011 +0100
    181 +++ b/wokkel/test/test_subprotocols.py  Fri Mar 04 09:45:24 2011 +0100
     176diff -r 6f36a7f92973 wokkel/test/test_subprotocols.py
     177--- a/wokkel/test/test_subprotocols.py  Thu Jul 28 20:14:02 2011 +0200
     178+++ b/wokkel/test/test_subprotocols.py  Wed Aug 03 09:45:01 2011 +0200
    182179@@ -9,12 +9,13 @@
    183180 
     
    196193 class DummyFactory(object):
    197194     """
    198 @@ -164,20 +165,48 @@
     195@@ -164,20 +165,46 @@
    199196 
    200197 
    201198 
    202199+class IQGetStanza(generic.Stanza):
    203 +    timeout = None
    204 +
    205200+    stanzaKind = 'iq'
    206201+    stanzaType = 'get'
     
    248243         self.assertEquals([], sm.handlers)
    249244         self.assertEquals(sm._connected,
    250 @@ -407,6 +436,7 @@
     245@@ -407,6 +434,7 @@
    251246         self.assertEquals(0, handler.nestedHandler.doneLost)
    252247 
     
    256251         """
    257252         Test removal of protocol handler.
    258 @@ -418,6 +448,7 @@
     253@@ -418,6 +446,7 @@
    259254         self.assertNotIn(handler, sm)
    260255         self.assertIdentical(None, handler.parent)
     
    264259         """
    265260         Test send when the stream has been initialized.
    266 @@ -509,6 +540,194 @@
     261@@ -509,6 +538,228 @@
    267262         self.assertEquals("<presence/>", sm._packetQueue[0])
    268263 
     
    449444+        d = self.streamManager.request(self.request)
    450445+
    451 +        xs = self.xmlstream
    452446+        self.xmlstream.connectionLost(failure.Failure(ConnectionDone()))
    453447+        self.assertFailure(d, ConnectionDone)
     
    456450+
    457451+
     452+    def test_requestNotIQ(self):
     453+        """
     454+        The request stanza must be an iq.
     455+        """
     456+        stanza = generic.Stanza()
     457+        stanza.stanzaKind = 'message'
     458+
     459+        d = self.streamManager.request(stanza)
     460+        self.assertFailure(d, ValueError)
     461+
     462+
     463+    def test_requestNotResult(self):
     464+        """
     465+        The request stanza cannot be of type 'result'.
     466+        """
     467+        stanza = generic.Stanza()
     468+        stanza.stanzaKind = 'iq'
     469+        stanza.stanzaType = 'result'
     470+
     471+        d = self.streamManager.request(stanza)
     472+        self.assertFailure(d, ValueError)
     473+
     474+
     475+    def test_requestNotError(self):
     476+        """
     477+        The request stanza cannot be of type 'error'.
     478+        """
     479+        stanza = generic.Stanza()
     480+        stanza.stanzaKind = 'iq'
     481+        stanza.stanzaType = 'error'
     482+
     483+        d = self.streamManager.request(stanza)
     484+        self.assertFailure(d, ValueError)
     485+
     486+
    458487 
    459488 class DummyIQHandler(subprotocols.IQHandlerMixin):
Note: See TracChangeset for help on using the changeset viewer.