Skip to content
Prev Previous commit
Next Next commit
correction in test_read_response_returns_cached_reply test case for n…
…ew redis_args field
  • Loading branch information
Shubham Kaudewar committed Sep 8, 2025
commit 3590399d30d7658df61f157b3500947010c59c78
25 changes: 15 additions & 10 deletions tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,12 +348,17 @@ def test_format_error_message(conn, error, expected_message):


def test_network_connection_failure():
exp_err = f"Error {ECONNREFUSED} connecting to localhost:9999. Connection refused."
# Match only the stable part of the error message across OS
exp_err = rf"Error {ECONNREFUSED} connecting to localhost:9999\."
with pytest.raises(ConnectionError, match=exp_err):
redis = Redis(port=9999)
redis.set("a", "b")


@pytest.mark.skipif(
not hasattr(socket, "AF_UNIX"),
reason="Unix domain sockets not supported on this platform"
)
def test_unix_socket_connection_failure():
exp_err = "Error 2 connecting to unix:///tmp/a.sock. No such file or directory."
with pytest.raises(ConnectionError, match=exp_err):
Expand Down Expand Up @@ -463,25 +468,25 @@ def test_read_response_returns_cached_reply(self, mock_cache, mock_connection):
None,
None,
CacheEntry(
cache_key=CacheKey(command="GET", redis_keys=("foo",)),
cache_key=CacheKey(command="GET", redis_keys=("foo",), redis_args=("GET", "foo")),
cache_value=CacheProxyConnection.DUMMY_CACHE_VALUE,
status=CacheEntryStatus.IN_PROGRESS,
connection_ref=mock_connection,
),
CacheEntry(
cache_key=CacheKey(command="GET", redis_keys=("foo",)),
cache_key=CacheKey(command="GET", redis_keys=("foo",), redis_args=("GET", "foo")),
cache_value=b"bar",
status=CacheEntryStatus.VALID,
connection_ref=mock_connection,
),
CacheEntry(
cache_key=CacheKey(command="GET", redis_keys=("foo",)),
cache_key=CacheKey(command="GET", redis_keys=("foo",), redis_args=("GET", "foo")),
cache_value=b"bar",
status=CacheEntryStatus.VALID,
connection_ref=mock_connection,
),
CacheEntry(
cache_key=CacheKey(command="GET", redis_keys=("foo",)),
cache_key=CacheKey(command="GET", redis_keys=("foo",), redis_args=("GET", "foo")),
cache_value=b"bar",
status=CacheEntryStatus.VALID,
connection_ref=mock_connection,
Expand All @@ -503,15 +508,15 @@ def test_read_response_returns_cached_reply(self, mock_cache, mock_connection):
[
call(
CacheEntry(
cache_key=CacheKey(command="GET", redis_keys=("foo",)),
cache_key=CacheKey(command="GET", redis_keys=("foo",), redis_args=("GET", "foo")),
cache_value=CacheProxyConnection.DUMMY_CACHE_VALUE,
status=CacheEntryStatus.IN_PROGRESS,
connection_ref=mock_connection,
)
),
call(
CacheEntry(
cache_key=CacheKey(command="GET", redis_keys=("foo",)),
cache_key=CacheKey(command="GET", redis_keys=("foo",), redis_args=("GET", "foo")),
cache_value=b"bar",
status=CacheEntryStatus.VALID,
connection_ref=mock_connection,
Expand All @@ -522,9 +527,9 @@ def test_read_response_returns_cached_reply(self, mock_cache, mock_connection):

mock_cache.get.assert_has_calls(
[
call(CacheKey(command="GET", redis_keys=("foo",))),
call(CacheKey(command="GET", redis_keys=("foo",))),
call(CacheKey(command="GET", redis_keys=("foo",))),
call(CacheKey(command="GET", redis_keys=("foo",), redis_args=("GET", "foo"))),
call(CacheKey(command="GET", redis_keys=("foo",), redis_args=("GET", "foo"))),
call(CacheKey(command="GET", redis_keys=("foo",), redis_args=("GET", "foo"))),
]
)

Expand Down
Loading