s.addBootstrap(xmlstream.STREAM_CONNECTED_EVENT, s.connectEvent)
s.addBootstrap(xmlstream.STREAM_ERROR_EVENT, s.streamError)
s.addBootstrap(xmlstream.STREAM_END_EVENT, s.connectError)
-
- if attrs.has_key('inactivity'):
- s.inactivity = attrs['inactivity']
- else:
- s.inactivity = 900 # 15 mins
-
+
+ s.inactivity = int(attrs.get('inactivity', 900)) # default inactivity 15 mins
+
s.secure = 0
s.use_raw = getattr(pint, 'use_raw', False) # use raw buffers
self.terminated = True
if self.verbose:
log.msg('SESSION -> Terminate')
+
# if there are any elements hanging around and waiting
# requests, send those off
self.returnWaitingRequests()
if not rid:
rid = self.rid - 1
self.appendWaitingRequest(d, rid)
-
+
# check if there is any data to send back to a request
self.returnWaitingRequests()
-
+
# make sure we aren't queueing too many requests
self.clearWaitingRequests(self.hold)
return d
Since the timeout function is called, we must return an empty
reply as there is no data to send back.
"""
-
# find the request that timed out and reply
pop_eye = []
for i in range(len(self.waiting_requests)):
return d
+
+ def testSessionTimeout(self):
+ """Test if we timeout correctly
+ """
+ d = defer.Deferred()
+
+ def testTimeout(res):
+ passed = True
+
+ if res.value[0]!='404':
+ passed = False
+ d.errback((Exception, 'Wrong Value %s '% (str(res.value),)))
+ if passed:
+ d.callback(True)
+ else:
+ log.err(res)
+
+ def testCBTimeout(res):
+ # check for terminate if we expire
+ terminate = res[0].getAttribute('type',False)
+
+ if str(terminate) != 'terminate':
+ d.errback((Exception, 'Was not terminate'))
+ return
+ d.callback(True)
+
+ def sendTest():
+ sd = self.send()
+ sd.addCallback(testCBTimeout)
+ sd.addErrback(testTimeout)
+
+
+ def testResend(res):
+ self.failUnless(res[0].name=='body', 'Wrong element')
+ s = self.b.service.sessions[self.sid]
+ self.failUnless(s.inactivity==10,'Wrong inactivity value')
+ self.failUnless(s.wait==10, 'Wrong wait value')
+ reactor.callLater(s.wait+s.inactivity+1, sendTest)
+
+
+ def testSessionCreate(res):
+ self.failUnless(res[0].name=='body', 'Wrong element')
+ self.failUnless(res[0].hasAttribute('sid'),'Not session id')
+ self.sid = res[0]['sid']
+
+ # send and wait
+ sd = self.send()
+
+ sd.addCallback(testResend)
+
+
+
+ BOSH_XML = """<body content='text/xml; charset=utf-8'
+ hold='1'
+ rid='%d'
+ to='localhost'
+ route='xmpp:127.0.0.1:5222'
+ ver='1.6'
+ wait='10'
+ ack='1'
+ inactivity='10'
+ xml:lang='en'
+ xmlns='http://jabber.org/protocol/httpbind'/>
+ """% (self.rid,)
+
+ self.proxy.connect(BOSH_XML).addCallback(testSessionCreate)
+ d.addErrback(self.fail)
+ return d
+
def testStreamError(self):
"""
This is to test if we get stream errors when there are no waiting requests.
return d
+
def testFeaturesError(self):
"""
This is to test if we get stream features and NOT twice