From 1e2665df19a866d5676abec566b9d8f190ecdc80 Mon Sep 17 00:00:00 2001 From: mathieui Date: Thu, 12 Feb 2015 12:23:47 +0100 Subject: 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 --- tests/test_stream_roster.py | 59 ++++++--------------------------------------- 1 file changed, 8 insertions(+), 51 deletions(-) (limited to 'tests/test_stream_roster.py') diff --git a/tests/test_stream_roster.py b/tests/test_stream_roster.py index a9aa15e1..6a171ce7 100644 --- a/tests/test_stream_roster.py +++ b/tests/test_stream_roster.py @@ -24,9 +24,7 @@ class TestStreamRoster(SlixTest): self.xmpp.add_event_handler('roster_update', roster_updates.append) - # Since get_roster blocks, we need to run it in a thread. - t = threading.Thread(name='get_roster', target=self.xmpp.get_roster) - t.start() + self.xmpp.get_roster() self.send(""" @@ -47,12 +45,6 @@ class TestStreamRoster(SlixTest): """) - # Wait for get_roster to return. - t.join() - - # Give the event queue time to process. - time.sleep(.1) - self.check_roster('tester@localhost', 'user@localhost', name='User', subscription='from', @@ -96,8 +88,6 @@ class TestStreamRoster(SlixTest): subscription='both', groups=['Friends', 'Examples']) - # Give the event queue time to process. - time.sleep(.1) self.failUnless('roster_update' in events, "Roster updated event not triggered: %s" % events) @@ -170,16 +160,6 @@ class TestStreamRoster(SlixTest): """) - def testRosterTimeout(self): - """Test handling a timed out roster request.""" - self.stream_start() - - def do_test(): - self.xmpp.get_roster(timeout=0) - time.sleep(.1) - - self.assertRaises(IqTimeout, do_test) - def testRosterCallback(self): """Test handling a roster request callback.""" self.stream_start() @@ -188,12 +168,7 @@ class TestStreamRoster(SlixTest): def roster_callback(iq): events.append('roster_callback') - # Since get_roster blocks, we need to run it in a thread. - t = threading.Thread(name='get_roster', - target=self.xmpp.get_roster, - kwargs={str('block'): False, - str('callback'): roster_callback}) - t.start() + self.xmpp.get_roster(callback=roster_callback) self.send(""" @@ -213,12 +188,6 @@ class TestStreamRoster(SlixTest): """) - # Wait for get_roster to return. - t.join() - - # Give the event queue time to process. - time.sleep(.1) - self.failUnless(events == ['roster_callback'], "Roster timeout event not triggered: %s." % events) @@ -235,9 +204,6 @@ class TestStreamRoster(SlixTest): """) - # Give the event queue time to process. - time.sleep(.1) - self.check_roster('tester@localhost', 'andré@foo', subscription='both', groups=['Unicode']) @@ -253,9 +219,6 @@ class TestStreamRoster(SlixTest): """) - # Give the event queue time to process. - time.sleep(.1) - result = self.xmpp.client_roster['andré@foo'].resources expected = {'bar': {'status':'Testing', 'show':'away', @@ -298,8 +261,8 @@ class TestStreamRoster(SlixTest): self.stream_start() self.assertTrue('rosterver' not in self.xmpp.features) - t = threading.Thread(name='get_roster', target=self.xmpp.get_roster) - t.start() + self.xmpp.get_roster() + self.send(""" @@ -309,16 +272,14 @@ class TestStreamRoster(SlixTest): """) - t.join() - def testBootstrapRosterVer(self): """Test bootstrapping with roster versioning.""" self.stream_start() self.xmpp.features.add('rosterver') self.xmpp.client_roster.version = '' - t = threading.Thread(name='get_roster', target=self.xmpp.get_roster) - t.start() + self.xmpp.get_roster() + self.send(""" @@ -328,8 +289,6 @@ class TestStreamRoster(SlixTest): """) - t.join() - def testExistingRosterVer(self): """Test using a stored roster version.""" @@ -337,8 +296,8 @@ class TestStreamRoster(SlixTest): self.xmpp.features.add('rosterver') self.xmpp.client_roster.version = '42' - t = threading.Thread(name='get_roster', target=self.xmpp.get_roster) - t.start() + self.xmpp.get_roster() + self.send(""" @@ -348,7 +307,5 @@ class TestStreamRoster(SlixTest): """) - t.join() - suite = unittest.TestLoader().loadTestsFromTestCase(TestStreamRoster) -- cgit v1.2.3