diff --git a/slixmpp/plugins/xep_0059/rsm.py b/slixmpp/plugins/xep_0059/rsm.py
index 00615ee4..61752af4 100644
--- a/slixmpp/plugins/xep_0059/rsm.py
+++ b/slixmpp/plugins/xep_0059/rsm.py
@@ -123,6 +123,8 @@ class ResultIterator(AsyncIterator):
self.query[self.interface]['rsm']['before'] = self.start
else:
self.query[self.interface]['rsm']['after'] = self.start
+ elif self.reverse:
+ self.query[self.interface]['rsm']['before'] = True
try:
if self.pre_cb:
diff --git a/tests/test_stream_xep_0030.py b/tests/test_stream_xep_0030.py
index 8cba8280..4cabfe38 100644
--- a/tests/test_stream_xep_0030.py
+++ b/tests/test_stream_xep_0030.py
@@ -512,30 +512,28 @@ class TestStreamDisco(SlixTest):
self.assertEqual(results, items,
"Unexpected items: %s" % results)
- '''
- def testGetItemsIterator(self):
+ def testGetItemsIterators(self):
"""Test interaction between XEP-0030 and XEP-0059 plugins."""
-
- raised_exceptions = []
+ iteration_finished = []
+ jids_found = set()
self.stream_start(mode='client',
plugins=['xep_0030', 'xep_0059'])
- results = self.xmpp['xep_0030'].get_items(jid='foo@localhost',
- node='bar',
- iterator=True)
- results.amount = 10
-
- def run_test():
- try:
- results.next()
- except StopIteration:
- raised_exceptions.append(True)
-
- t = threading.Thread(name="get_items_iterator",
- target=run_test)
- t.start()
+ async def run_test():
+ iterator = await self.xmpp['xep_0030'].get_items(
+ jid='foo@localhost',
+ node='bar',
+ iterator=True
+ )
+ iterator.amount = 10
+ async for page in iterator:
+ for item in page['disco_items']['items']:
+ jids_found.add(item[0])
+ iteration_finished.append(True)
+ test_run = self.xmpp.wrap(run_test())
+ self.wait_()
self.send("""
+
+
+
+
+
+ a@b
+ e@b
+ 10
""")
-
- t.join()
-
- self.assertEqual(raised_exceptions, [True],
- "StopIteration was not raised: %s" % raised_exceptions)
- '''
+ self.wait_()
+ self.send("""
+
+
+
+ 10
+ e@b
+
+
+
+ """)
+ self.recv("""
+
+
+
+
+
+
+
+
+ f@b
+ j@b
+ 10
+
+
+
+ """)
+ expected_jids = {'%s@b' % i for i in 'abcdefghij'}
+ self.run_coro(test_run)
+ self.assertEqual(expected_jids, jids_found)
+ self.assertEqual(iteration_finished, [True])
suite = unittest.TestLoader().loadTestsFromTestCase(TestStreamDisco)