summaryrefslogtreecommitdiff
path: root/tests/test_stream_handlers.py
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2015-02-12 12:23:47 +0100
committermathieui <mathieui@mathieui.net>2015-02-12 12:23:47 +0100
commit1e2665df19a866d5676abec566b9d8f190ecdc80 (patch)
tree9fe2f0c501d376291f3d9efc3e9550b34afbf6c7 /tests/test_stream_handlers.py
parent4d063e287e1bb2010d115325a3c8c6ca7c542bfc (diff)
downloadslixmpp-1e2665df19a866d5676abec566b9d8f190ecdc80.tar.gz
slixmpp-1e2665df19a866d5676abec566b9d8f190ecdc80.tar.bz2
slixmpp-1e2665df19a866d5676abec566b9d8f190ecdc80.tar.xz
slixmpp-1e2665df19a866d5676abec566b9d8f190ecdc80.zip
Update the test suite.
- monkey-patch our own monkey-patched idle_call to run events immediatly rather than adding them to the event queue, and add a fake transport with a fake socket. - remove the test file related to xep_0059 as it relies on blocking behavior, and comment out one xep_0030 test uses xep_0059 - remove many instances of threading and sleep()s because they do nothing except waste time and introduce race conditions. - keep exactly two sleep() in IoT xeps because they rely on timeouts
Diffstat (limited to 'tests/test_stream_handlers.py')
-rw-r--r--tests/test_stream_handlers.py70
1 files changed, 13 insertions, 57 deletions
diff --git a/tests/test_stream_handlers.py b/tests/test_stream_handlers.py
index 61cb68a7..24b5c1a6 100644
--- a/tests/test_stream_handlers.py
+++ b/tests/test_stream_handlers.py
@@ -48,15 +48,15 @@ class TestHandlers(SlixTest):
iq['id'] = 'test'
iq['type'] = 'set'
iq['query'] = 'test'
- reply = iq.send(block=True)
- if reply:
+ def callback_waiter(result):
self.xmpp.send_raw("""
<message>
<body>Successful: %s</body>
</message>
- """ % reply['query'])
+ """ % result['query'])
+ iq.send(callback=callback_waiter)
- self.xmpp.add_event_handler('message', waiter_handler, threaded=True)
+ self.xmpp.add_event_handler('message', waiter_handler)
# Send message to trigger waiter_handler
self.recv("""
@@ -93,11 +93,11 @@ class TestHandlers(SlixTest):
iq['type'] = 'set'
iq['query'] = 'test2'
try:
- reply = iq.send(block=True, timeout=0)
+ reply = iq.send(timeout=0)
except IqTimeout:
pass
- self.xmpp.add_event_handler('message', waiter_handler, threaded=True)
+ self.xmpp.add_event_handler('message', waiter_handler)
# Start test by triggerig waiter_handler
self.recv("""<message><body>Start Test</body></message>""")
@@ -109,9 +109,6 @@ class TestHandlers(SlixTest):
iq['query'] = 'test2'
self.send(iq)
- # Give the event queue time to process.
- time.sleep(0.1)
-
# Check that the waiter is no longer registered
waiter_exists = self.xmpp.remove_handler('IqWait_test2')
@@ -148,41 +145,9 @@ class TestHandlers(SlixTest):
</iq>
""")
- # Give event queue time to process
- time.sleep(0.1)
-
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("""
- <iq type="get" id="test-foo" to="user@localhost">
- <query xmlns="foo" />
- </iq>
- """)
-
- # Give event queue time to process
- time.sleep(1)
-
- self.failUnless(events == ['timeout'],
- "Iq timeout was not executed: %s" % events)
-
def testMultipleHandlersForStanza(self):
"""
Test that multiple handlers for a single stanza work
@@ -235,18 +200,15 @@ class TestHandlers(SlixTest):
events = []
- def run_test():
- # Check that Iq was sent by waiter_handler
- iq = self.Iq()
- iq['id'] = 'test'
- iq['to'] = 'tester@slixmpp.com/test'
- iq['type'] = 'set'
- iq['query'] = 'test'
- result = iq.send()
+ def callback(result):
events.append(result['from'].full)
- t = threading.Thread(name="sender_test", target=run_test)
- t.start()
+ iq = self.Iq()
+ iq['id'] = 'test'
+ iq['to'] = 'tester@slixmpp.com/test'
+ iq['type'] = 'set'
+ iq['query'] = 'test'
+ iq.send(callback=callback)
self.recv("""
<iq id="test" from="evil@slixmpp.com/bad" type="result">
@@ -271,13 +233,7 @@ class TestHandlers(SlixTest):
</iq>
""")
- t.join()
-
- time.sleep(0.1)
-
self.assertEqual(events, ['tester@slixmpp.com/test'], "Did not timeout on bad sender")
-
-
suite = unittest.TestLoader().loadTestsFromTestCase(TestHandlers)