Changeset 53:fd2b3f70b221 in ralphm-patches for request-tracking.patch
- Timestamp:
- Aug 3, 2011, 9:48:58 AM (11 years ago)
- Branch:
- default
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
request-tracking.patch
r47 r53 1 1 # HG changeset patch 2 # Parent 6 0dcf9e2441bb510f1da17e6bc4401ef7b6db0e92 # Parent 6f36a7f92973d3843a42b4c80791715e694b66a3 3 3 Add iq request (set/get) tracking for StreamManager. 4 4 … … 20 20 from the moment request is sent over the wire. 21 21 22 diff -r 6 0dcf9e2441bwokkel/subprotocols.py23 --- a/wokkel/subprotocols.py Mon Feb 28 21:04:37 2011 +010024 +++ b/wokkel/subprotocols.py Fri Mar 04 09:45:24 2011 +010022 diff -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 25 25 @@ -156,11 +156,23 @@ 26 26 @type _initialized: C{bool} … … 73 73 for p in self._packetQueue: 74 74 xs.send(p) 75 @@ -268,6 +291,3 4@@75 @@ -268,6 +291,31 @@ 76 76 for e in list(self): 77 77 e.connectionLost(reason) … … 90 90 + Handle iq response by firing associated deferred. 91 91 + """ 92 + if getattr(iq, 'handled', False):93 + return94 +95 92 + try: 96 93 + d = self._iqDeferreds[iq["id"]] … … 108 105 def send(self, obj): 109 106 """ 110 @@ -285,6 +33 6,68 @@107 @@ -285,6 +333,68 @@ 111 108 self._packetQueue.append(obj) 112 109 … … 141 138 + if (request.stanzaKind != 'iq' or 142 139 + request.stanzaType not in ('get', 'set')): 143 + return defer.fail( Exception("Not a request"))140 + return defer.fail(ValueError("Not a request")) 144 141 + 145 142 + element = request.toElement() … … 154 151 + self._iqDeferreds[element['id']] = d 155 152 + 156 + timeout = request.timeout or self.timeout153 + timeout = getattr(request, 'timeout', self.timeout) 157 154 + 158 155 + if timeout is not None: … … 177 174 class IQHandlerMixin(object): 178 175 """ 179 diff -r 6 0dcf9e2441bwokkel/test/test_subprotocols.py180 --- a/wokkel/test/test_subprotocols.py Mon Feb 28 21:04:37 2011 +0100181 +++ b/wokkel/test/test_subprotocols.py Fri Mar 04 09:45:24 2011 +0100176 diff -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 182 179 @@ -9,12 +9,13 @@ 183 180 … … 196 193 class DummyFactory(object): 197 194 """ 198 @@ -164,20 +165,4 8@@195 @@ -164,20 +165,46 @@ 199 196 200 197 201 198 202 199 +class IQGetStanza(generic.Stanza): 203 + timeout = None204 +205 200 + stanzaKind = 'iq' 206 201 + stanzaType = 'get' … … 248 243 self.assertEquals([], sm.handlers) 249 244 self.assertEquals(sm._connected, 250 @@ -407,6 +43 6,7 @@245 @@ -407,6 +434,7 @@ 251 246 self.assertEquals(0, handler.nestedHandler.doneLost) 252 247 … … 256 251 """ 257 252 Test removal of protocol handler. 258 @@ -418,6 +44 8,7 @@253 @@ -418,6 +446,7 @@ 259 254 self.assertNotIn(handler, sm) 260 255 self.assertIdentical(None, handler.parent) … … 264 259 """ 265 260 Test send when the stream has been initialized. 266 @@ -509,6 +5 40,194@@261 @@ -509,6 +538,228 @@ 267 262 self.assertEquals("<presence/>", sm._packetQueue[0]) 268 263 … … 449 444 + d = self.streamManager.request(self.request) 450 445 + 451 + xs = self.xmlstream452 446 + self.xmlstream.connectionLost(failure.Failure(ConnectionDone())) 453 447 + self.assertFailure(d, ConnectionDone) … … 456 450 + 457 451 + 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 + 458 487 459 488 class DummyIQHandler(subprotocols.IQHandlerMixin):
Note: See TracChangeset
for help on using the changeset viewer.