diff options
author | Shalabh Chaturvedi <shalabh.chaturvedi+github@gmail.com> | 2022-08-25 10:47:52 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-25 23:47:52 +0600 |
commit | ec533af9c1c6e156a1fe754fddc2095ebdba8554 (patch) | |
tree | 38279c9ff6946cd9112bd19c2a61f6fe28a66626 | |
parent | 717ad3ddc98d83a7b9e2cb7054bb92a0cd6c8d53 (diff) | |
download | kombu-ec533af9c1c6e156a1fe754fddc2095ebdba8554.tar.gz |
Fix incompatibility with redis in disconnect() (#1589)
* Accept *args in disconnect()
* Add test for redis connection timeout error
-rw-r--r-- | kombu/transport/redis.py | 4 | ||||
-rw-r--r-- | t/integration/test_redis.py | 16 |
2 files changed, 18 insertions, 2 deletions
diff --git a/kombu/transport/redis.py b/kombu/transport/redis.py index 57a5a63b..6cbfbdcf 100644 --- a/kombu/transport/redis.py +++ b/kombu/transport/redis.py @@ -1185,8 +1185,8 @@ class Channel(virtual.Channel): if asynchronous: class Connection(connection_cls): - def disconnect(self): - super().disconnect() + def disconnect(self, *args): + super().disconnect(*args) channel._on_connection_disconnect(self) connection_cls = Connection diff --git a/t/integration/test_redis.py b/t/integration/test_redis.py index 169a32dc..b2ae5ab8 100644 --- a/t/integration/test_redis.py +++ b/t/integration/test_redis.py @@ -1,6 +1,7 @@ from __future__ import annotations import os +import socket from time import sleep import pytest @@ -134,3 +135,18 @@ class test_RedisPriority(BasePriority): @pytest.mark.flaky(reruns=5, reruns_delay=2) class test_RedisMessage(BaseMessage): pass + + +@pytest.mark.env('redis') +def test_RedisConnectTimeout(monkeypatch): + # simulate a connection timeout for a new connection + def connect_timeout(self): + raise socket.timeout + monkeypatch.setattr( + redis.connection.Connection, "_connect", connect_timeout) + + # ensure the timeout raises a TimeoutError + with pytest.raises(redis.exceptions.TimeoutError): + # note the host/port here is irrelevant because + # connect will raise a socket.timeout + kombu.Connection('redis://localhost:12345').connect() |