Skip to content

Commit

Permalink
Fix incompatibility with redis in disconnect() (#1589)
Browse files Browse the repository at this point in the history
* Accept *args in disconnect()

* Add test for redis connection timeout error
  • Loading branch information
shalabhc authored Aug 25, 2022
1 parent 717ad3d commit ec533af
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions kombu/transport/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1185,8 +1185,8 @@ def _connparams(self, asynchronous=False):

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

Expand Down
16 changes: 16 additions & 0 deletions t/integration/test_redis.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import os
import socket
from time import sleep

import pytest
Expand Down Expand Up @@ -134,3 +135,18 @@ def callback(body, message):
@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()

0 comments on commit ec533af

Please sign in to comment.