From 98bc9cc558e6857641ff72c066434958a03aed9f Mon Sep 17 00:00:00 2001 From: Min RK Date: Wed, 21 Aug 2024 11:00:28 +0200 Subject: [PATCH] avoid warnings in redis cleanup - redis.close deprecated in favor of redis.aclose - make sure to close external redis proxy client to avoid warnings during teardown --- jupyterhub_traefik_proxy/redis.py | 7 ++++++- tests/conftest.py | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/jupyterhub_traefik_proxy/redis.py b/jupyterhub_traefik_proxy/redis.py index 7bc1bb67..af63d9c6 100644 --- a/jupyterhub_traefik_proxy/redis.py +++ b/jupyterhub_traefik_proxy/redis.py @@ -70,7 +70,12 @@ async def _cleanup(self): f = super()._cleanup() if f is not None: await f - await self.redis.close() + if hasattr(self.redis, 'aclose'): + aclose = self.redis.aclose + else: + # redis < 5.0.1 + aclose = self.redis.close + await aclose() def _setup_traefik_static_config(self): self.log.debug("Setting up the redis provider in the traefik static config") diff --git a/tests/conftest.py b/tests/conftest.py index 6c59c0d6..14c0fc75 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -418,6 +418,7 @@ async def external_redis_proxy(launch_traefik_redis, proxy_args): ) await proxy._start_future yield proxy + await proxy._cleanup() @pytest.fixture @@ -801,6 +802,7 @@ async def _wait_for_redis(): from redis.asyncio import Redis async def _check_redis(): + r = None try: r = Redis( port=Config.redis_port, @@ -811,6 +813,10 @@ async def _check_redis(): except redis.exceptions.ConnectionError as e: print(e) return False + finally: + if r is not None: + await r.aclose() + return True await exponential_backoff(