From 67235c42145ef40d841e9cb7ffa4bbcac490568a Mon Sep 17 00:00:00 2001 From: Joe Hildebrand Date: Mon, 29 Oct 2012 10:03:32 -0600 Subject: Allow IQ timeouts to be asynchronous, by passing a timeout_callback parameter to send(). An example modification of disco is included. If this approach is approved, I'll go through and update the other plugins. --- tests/test_stream_handlers.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'tests') diff --git a/tests/test_stream_handlers.py b/tests/test_stream_handlers.py index 7fd4e648..cdd128bb 100644 --- a/tests/test_stream_handlers.py +++ b/tests/test_stream_handlers.py @@ -153,6 +153,35 @@ class TestHandlers(SleekTest): self.failUnless(events == ['foo'], "Iq callback was not executed: %s" % events) + def testIqTimeoutCallback(self): + """Test that iq.send(tcallback=handle_foo, timeout_callback=handle_timeout) works.""" + events = [] + + def handle_foo(iq): + events.append('foo') + + def handle_timeout(iq): + events.append('timeout') + + iq = self.Iq() + iq['type'] = 'get' + iq['id'] = 'test-foo' + iq['to'] = 'user@localhost' + iq['query'] = 'foo' + iq.send(callback=handle_foo, timeout_callback=handle_timeout, timeout=0.05) + + self.send(""" + + + + """) + + # Give event queue time to process + time.sleep(0.1) + + self.failUnless(events == ['timeout'], + "Iq timeout was not executed: %s" % events) + def testMultipleHandlersForStanza(self): """ Test that multiple handlers for a single stanza work -- cgit v1.2.3 From 2229ad8d8e51b73a7900b118dfab5d7b449f17ce Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Wed, 31 Oct 2012 13:41:55 -0700 Subject: Relax timing issues in Iq timeout callback test. --- tests/test_stream_handlers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/test_stream_handlers.py b/tests/test_stream_handlers.py index cdd128bb..d3850a94 100644 --- a/tests/test_stream_handlers.py +++ b/tests/test_stream_handlers.py @@ -177,7 +177,7 @@ class TestHandlers(SleekTest): """) # Give event queue time to process - time.sleep(0.1) + time.sleep(1) self.failUnless(events == ['timeout'], "Iq timeout was not executed: %s" % events) -- cgit v1.2.3