From be6dde17f16e85b50361a3db243e9b2e40b2cb5d Mon Sep 17 00:00:00 2001 From: mathieui Date: Mon, 13 Dec 2021 21:25:41 +0100 Subject: [PATCH 1/6] Revert "Replace asyncio.ensure_future() with asyncio.create_task()" This reverts commit bac6a4b2bf2fc98401e0de7168c4a5cf31b08b37. This is not actually something we want --- slixmpp/plugins/xep_0045/muc.py | 2 +- slixmpp/plugins/xep_0163.py | 4 ++-- slixmpp/plugins/xep_0199/ping.py | 2 +- slixmpp/test/slixtest.py | 2 +- slixmpp/xmlstream/handler/coroutine_callback.py | 6 +++--- slixmpp/xmlstream/xmlstream.py | 16 ++++++++-------- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/slixmpp/plugins/xep_0045/muc.py b/slixmpp/plugins/xep_0045/muc.py index bfb8e571..21f5c896 100644 --- a/slixmpp/plugins/xep_0045/muc.py +++ b/slixmpp/plugins/xep_0045/muc.py @@ -342,7 +342,7 @@ class XEP_0045(BasePlugin): maxchars = 9 else: maxstanzas = int(maxhistory) - return asyncio.create_task( + return asyncio.ensure_future( self.join_muc_wait( room=room, nick=nick, diff --git a/slixmpp/plugins/xep_0163.py b/slixmpp/plugins/xep_0163.py index 07cef975..46ca4235 100644 --- a/slixmpp/plugins/xep_0163.py +++ b/slixmpp/plugins/xep_0163.py @@ -61,7 +61,7 @@ class XEP_0163(BasePlugin): for ns in namespace: self.xmpp['xep_0030'].add_feature('%s+notify' % ns, jid=jid) - asyncio.create_task( + asyncio.ensure_future( self.xmpp['xep_0115'].update_caps(jid, broadcast=False), loop=self.xmpp.loop, ) @@ -82,7 +82,7 @@ class XEP_0163(BasePlugin): for ns in namespace: self.xmpp['xep_0030'].del_feature(jid=jid, feature='%s+notify' % namespace) - asyncio.create_task( + asyncio.ensure_future( self.xmpp['xep_0115'].update_caps(jid, broadcast=False), loop=self.xmpp.loop, ) diff --git a/slixmpp/plugins/xep_0199/ping.py b/slixmpp/plugins/xep_0199/ping.py index 11234bab..03d272dd 100644 --- a/slixmpp/plugins/xep_0199/ping.py +++ b/slixmpp/plugins/xep_0199/ping.py @@ -118,7 +118,7 @@ class XEP_0199(BasePlugin): tmp_futures.append(future) self.__pending_futures = tmp_futures - future = asyncio.create_task( + future = asyncio.ensure_future( self._keepalive(event), loop=self.xmpp.loop, ) diff --git a/slixmpp/test/slixtest.py b/slixmpp/test/slixtest.py index 1c7f12fa..0d05a4ac 100644 --- a/slixmpp/test/slixtest.py +++ b/slixmpp/test/slixtest.py @@ -622,7 +622,7 @@ class SlixTest(unittest.TestCase): def wait_for_send_queue(self): loop = asyncio.get_event_loop() - future = asyncio.create_task(self.xmpp.run_filters(), loop=loop) + future = asyncio.ensure_future(self.xmpp.run_filters(), loop=loop) queue = self.xmpp.waiting_queue loop.run_until_complete(queue.join()) future.cancel() diff --git a/slixmpp/xmlstream/handler/coroutine_callback.py b/slixmpp/xmlstream/handler/coroutine_callback.py index 1ebe3ae4..524cca54 100644 --- a/slixmpp/xmlstream/handler/coroutine_callback.py +++ b/slixmpp/xmlstream/handler/coroutine_callback.py @@ -6,7 +6,7 @@ # :license: MIT, see LICENSE for more details from __future__ import annotations -import asyncio +from asyncio import iscoroutinefunction, ensure_future from typing import Optional, Callable, Awaitable, TYPE_CHECKING from slixmpp.xmlstream.stanzabase import StanzaBase @@ -52,7 +52,7 @@ class CoroutineCallback(BaseHandler): pointer: CoroutineFunction, once: bool = False, instream: bool = False, stream: Optional[XMLStream] = None): BaseHandler.__init__(self, name, matcher, stream) - if not asyncio.iscoroutinefunction(pointer): + if not iscoroutinefunction(pointer): raise ValueError("Given function is not a coroutine") async def pointer_wrapper(stanza: StanzaBase) -> None: @@ -87,7 +87,7 @@ class CoroutineCallback(BaseHandler): :meth:`prerun()`. Defaults to ``False``. """ if not self._instream or instream: - asyncio.create_task(self._pointer(payload)) + ensure_future(self._pointer(payload)) if self._once: self._destroy = True del self._pointer diff --git a/slixmpp/xmlstream/xmlstream.py b/slixmpp/xmlstream/xmlstream.py index 9955360a..30f99071 100644 --- a/slixmpp/xmlstream/xmlstream.py +++ b/slixmpp/xmlstream/xmlstream.py @@ -415,7 +415,7 @@ class XMLStream(asyncio.BaseProtocol): """ if self._run_out_filters is None or self._run_out_filters.done(): - self._run_out_filters = asyncio.create_task( + self._run_out_filters = asyncio.ensure_future( self.run_filters(), loop=self.loop, ) @@ -439,7 +439,7 @@ class XMLStream(asyncio.BaseProtocol): self.disable_starttls = disable_starttls self.event("connecting") - self._current_connection_attempt = asyncio.create_task( + self._current_connection_attempt = asyncio.ensure_future( self._connect_routine(), loop=self.loop, ) @@ -486,7 +486,7 @@ class XMLStream(asyncio.BaseProtocol): if self._current_connection_attempt is None: return self._connect_loop_wait = self._connect_loop_wait * 2 + 1 - self._current_connection_attempt = asyncio.create_task( + self._current_connection_attempt = asyncio.ensure_future( self._connect_routine(), loop=self.loop, ) @@ -653,12 +653,12 @@ class XMLStream(asyncio.BaseProtocol): self.disconnect_reason = reason if self.waiting_queue.empty() or ignore_send_queue: self.cancel_connection_attempt() - return asyncio.create_task( + return asyncio.ensure_future( self._end_stream_wait(wait, reason=reason), loop=self.loop, ) else: - return asyncio.create_task( + return asyncio.ensure_future( self._consume_send_queue_before_disconnecting(reason, wait), loop=self.loop, ) @@ -1058,7 +1058,7 @@ class XMLStream(asyncio.BaseProtocol): old_exception(e) else: self.exception(e) - asyncio.create_task( + asyncio.ensure_future( handler_callback_routine(handler_callback), loop=self.loop, ) @@ -1224,7 +1224,7 @@ class XMLStream(asyncio.BaseProtocol): ) if pending: self.__slow_tasks.append(task) - asyncio.create_task( + asyncio.ensure_future( self._continue_slow_send( task, already_run_filters @@ -1431,7 +1431,7 @@ class XMLStream(asyncio.BaseProtocol): :param coroutine: The coroutine to wrap. """ - return asyncio.create_task( + return asyncio.ensure_future( coroutine, loop=self.loop, ) From 799a6a07a98d708d0645fad0343177526128974c Mon Sep 17 00:00:00 2001 From: mathieui Date: Mon, 13 Dec 2021 21:31:30 +0100 Subject: [PATCH 2/6] fix: remove loop parameter when deprecated (3.10) --- slixmpp/plugins/xep_0030/disco.py | 1 - slixmpp/plugins/xep_0047/stream.py | 2 +- slixmpp/xmlstream/handler/waiter.py | 2 +- slixmpp/xmlstream/xmlstream.py | 8 ++++---- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/slixmpp/plugins/xep_0030/disco.py b/slixmpp/plugins/xep_0030/disco.py index 0fa09927..37d453aa 100644 --- a/slixmpp/plugins/xep_0030/disco.py +++ b/slixmpp/plugins/xep_0030/disco.py @@ -326,7 +326,6 @@ class XEP_0030(BasePlugin): info_futures, _ = await asyncio.wait( infos, timeout=timeout, - loop=self.xmpp.loop ) self.domain_infos[domain] = [ diff --git a/slixmpp/plugins/xep_0047/stream.py b/slixmpp/plugins/xep_0047/stream.py index f020ea68..0cda5dd9 100644 --- a/slixmpp/plugins/xep_0047/stream.py +++ b/slixmpp/plugins/xep_0047/stream.py @@ -115,7 +115,7 @@ class IBBytestream(object): self.xmpp.add_event_handler('ibb_stream_end', on_close) self.xmpp.add_event_handler('ibb_stream_data', on_data) try: - await asyncio.wait_for(end_future, timeout, loop=self.xmpp.loop) + await asyncio.wait_for(end_future, timeout) except asyncio.TimeoutError: raise IqTimeout(result) finally: diff --git a/slixmpp/xmlstream/handler/waiter.py b/slixmpp/xmlstream/handler/waiter.py index dde49754..599004b5 100644 --- a/slixmpp/xmlstream/handler/waiter.py +++ b/slixmpp/xmlstream/handler/waiter.py @@ -80,7 +80,7 @@ class Waiter(BaseHandler): try: await wait_for( - self._event.wait(), timeout, loop=stream.loop + self._event.wait(), timeout, ) except TimeoutError: log.warning("Timed out waiting for %s", self.name) diff --git a/slixmpp/xmlstream/xmlstream.py b/slixmpp/xmlstream/xmlstream.py index 30f99071..256eb2dc 100644 --- a/slixmpp/xmlstream/xmlstream.py +++ b/slixmpp/xmlstream/xmlstream.py @@ -449,7 +449,7 @@ class XMLStream(asyncio.BaseProtocol): if self._connect_loop_wait > 0: self.event('reconnect_delay', self._connect_loop_wait) - await asyncio.sleep(self._connect_loop_wait, loop=self.loop) + await asyncio.sleep(self._connect_loop_wait) record = await self._pick_dns_answer(self.default_domain) if record is not None: @@ -504,10 +504,10 @@ class XMLStream(asyncio.BaseProtocol): else: self.loop.run_until_complete(self.disconnected) else: - tasks: List[Future] = [asyncio.sleep(timeout, loop=self.loop)] + tasks: List[Future] = [asyncio.sleep(timeout)] if not forever: tasks.append(self.disconnected) - self.loop.run_until_complete(asyncio.wait(tasks, loop=self.loop)) + self.loop.run_until_complete(asyncio.wait(tasks)) def init_parser(self) -> None: """init the XML parser. The parser must always be reset for each new @@ -715,7 +715,7 @@ class XMLStream(asyncio.BaseProtocol): log.debug("reconnecting...") async def handler(event: Any) -> None: # We yield here to allow synchronous handlers to work first - await asyncio.sleep(0, loop=self.loop) + await asyncio.sleep(0) self.connect() self.add_event_handler('disconnected', handler, disposable=True) self.disconnect(wait, reason) From 4ca1de92b3e4f58ced179fcefa877184bf421232 Mon Sep 17 00:00:00 2001 From: mathieui Date: Mon, 13 Dec 2021 22:35:53 +0100 Subject: [PATCH 3/6] fix: integration tests prosody got more restrictive? --- itests/test_pep.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/itests/test_pep.py b/itests/test_pep.py index a674a348..382c22b6 100644 --- a/itests/test_pep.py +++ b/itests/test_pep.py @@ -34,7 +34,14 @@ class TestPEP(SlixIntegration): """Check we can get and set public PEP data""" stanza = Mystanza() stanza['test'] = str(uuid4().hex) - await self.clients[0]['xep_0222'].store(stanza, id='toto') + try: + await self.clients[0]['xep_0060'].delete_node( + self.clients[0].boundjid.bare, + node=stanza.namespace, + ) + except: + pass + await self.clients[0]['xep_0222'].store(stanza, node=stanza.namespace, id='toto') fetched = await self.clients[0]['xep_0222'].retrieve( stanza.namespace, ) From e1b135c667447c157c87ac7de6a1b8913aa02166 Mon Sep 17 00:00:00 2001 From: mathieui Date: Mon, 13 Dec 2021 22:37:07 +0100 Subject: [PATCH 4/6] ci: only run integration tests once --- .gitlab-ci.yml | 52 +++++++++++++++++++++----------------------------- 1 file changed, 22 insertions(+), 30 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a622deb6..ac5a8b62 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -23,6 +23,28 @@ test: - pip3 install emoji aiohttp - ./run_tests.py +test-3.10: + stage: test + tags: + - docker + image: python:3.10 + script: + - apt update + - apt install -y python3 python3-pip cython3 gpg + - pip3 install emoji aiohttp + - ./run_tests.py + +test-3.11: + stage: test + tags: + - docker + image: python:3.11-rc + script: + - apt update + - apt install -y python3 python3-pip cython3 gpg + - pip3 install emoji aiohttp + - ./run_tests.py + test_integration: stage: test tags: @@ -38,36 +60,6 @@ test_integration: - pip3 install emoji aiohttp aiodns - ./run_integration_tests.py -test_integration-3.10: - stage: test - tags: - - docker - image: python:3.10 - only: - variables: - - $CI_ACCOUNT1 - - $CI_ACCOUNT2 - script: - - apt update - - apt install -y python3 python3-pip cython3 gpg - - pip3 install emoji aiohttp aiodns - - ./run_integration_tests.py - -test_integration-3.11: - stage: test - tags: - - docker - image: python:3.11-rc - only: - variables: - - $CI_ACCOUNT1 - - $CI_ACCOUNT2 - script: - - apt update - - apt install -y python3 python3-pip cython3 gpg - - pip3 install emoji aiohttp aiodns - - ./run_integration_tests.py - trigger_poezio: stage: trigger tags: From 8ba054dd532c80f0c109ad4ec41d4099b690a927 Mon Sep 17 00:00:00 2001 From: mathieui Date: Mon, 13 Dec 2021 22:43:52 +0100 Subject: [PATCH 5/6] ci: allow failure in python 3.11 for now --- .gitlab-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ac5a8b62..f67235fa 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -39,6 +39,7 @@ test-3.11: tags: - docker image: python:3.11-rc + allow_failure: true script: - apt update - apt install -y python3 python3-pip cython3 gpg From 0e5a4726af81dcbb8db11eeb5fa1852c9122db24 Mon Sep 17 00:00:00 2001 From: mathieui Date: Mon, 13 Dec 2021 23:08:55 +0100 Subject: [PATCH 6/6] ci: fix curl image to an official one --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f67235fa..69bd7b7a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -65,6 +65,6 @@ trigger_poezio: stage: trigger tags: - docker - image: appropriate/curl:latest + image: curlimages/curl:7.79.1 script: - curl --request POST -F token="$SLIXMPP_TRIGGER_TOKEN" -F ref=master https://lab.louiz.org/api/v4/projects/18/trigger/pipeline