Fix errors in testSessionTimeout cause long timeouts.
authorGlenn Maynard <glenn@zewt.org>
Fri, 29 Apr 2011 00:18:13 +0000 (20:18 -0400)
committerGlenn Maynard <glenn@zewt.org>
Fri, 29 Apr 2011 00:18:13 +0000 (20:18 -0400)
Errors in this test are being raised from within callbacks which
are being fired on Deferred objects other than the one returned
from the test itself.  This causes the test runner to never see
them, so the test sits around until the whole test times out.

Fix this by adding an errback to the two separate Deferred objects,
which simply forwards the error onto the primary Deferred.

Lower the timeout from 10*2 seconds to 2*2 seconds.  This is an
improvement, but the test is still cumbersome to run.  Maybe tests
that depend on timeouts should be moved to their own test class,
so it's possible to run the fast tests quickly.

tests/xep124.py

index bd2d913..7d2ff56 100644 (file)
@@ -127,6 +127,10 @@ class XEP0124TestCase(test_basic.TestCase):
         """
         d = defer.Deferred()
 
+        # If an error occurs within the current Deferred, propagate it to d.
+        def propagateError(e):
+            d.errback(e)
+
         def testTimeout(res):
             passed = True
             
@@ -156,8 +160,8 @@ class XEP0124TestCase(test_basic.TestCase):
         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')
+            self.failUnless(s.inactivity==2,'Wrong inactivity value')
+            self.failUnless(s.wait==2, 'Wrong wait value')
             reactor.callLater(s.wait+s.inactivity+1, sendTest)
             
 
@@ -169,7 +173,7 @@ class XEP0124TestCase(test_basic.TestCase):
             # send and wait 
             sd = self.send()
             
-            sd.addCallback(testResend)
+            sd.addCallbacks(testResend, propagateError)
             
 
 
@@ -179,14 +183,14 @@ class XEP0124TestCase(test_basic.TestCase):
       to='localhost'
       route='xmpp:127.0.0.1:%(server_port)i'
       ver='1.6'
-      wait='10'
+      wait='2'
       ack='1'
-      inactivity='10'
+      inactivity='2'
       xml:lang='en'
       xmlns='http://jabber.org/protocol/httpbind'/>
  """% { "rid": self.rid, "server_port": self.server_port }
 
-        self.proxy.connect(BOSH_XML).addCallback(testSessionCreate)
+        self.proxy.connect(BOSH_XML).addCallbacks(testSessionCreate, propagateError)
         d.addErrback(self.fail)
         return d