summaryrefslogtreecommitdiff
path: root/tests/test_asyncio/test_connection.py
diff options
context:
space:
mode:
authorAndrew Chen Wang <60190294+Andrew-Chen-Wang@users.noreply.github.com>2022-02-22 05:29:55 -0500
committerGitHub <noreply@github.com>2022-02-22 12:29:55 +0200
commitd56baeb683fc1935cfa343fa2eeb0fa9bd955283 (patch)
tree47357a74bf1d1428cfbcf0d8b2c781f1f971cf77 /tests/test_asyncio/test_connection.py
parente3c989d93e914e6502bd5a72f15ded49a135c5be (diff)
downloadredis-py-d56baeb683fc1935cfa343fa2eeb0fa9bd955283.tar.gz
Add Async Support (#1899)
Co-authored-by: Chayim I. Kirshen <c@kirshen.com> Co-authored-by: dvora-h <dvora.heller@redis.com>
Diffstat (limited to 'tests/test_asyncio/test_connection.py')
-rw-r--r--tests/test_asyncio/test_connection.py64
1 files changed, 64 insertions, 0 deletions
diff --git a/tests/test_asyncio/test_connection.py b/tests/test_asyncio/test_connection.py
new file mode 100644
index 0000000..46abec0
--- /dev/null
+++ b/tests/test_asyncio/test_connection.py
@@ -0,0 +1,64 @@
+import asyncio
+import types
+
+import pytest
+
+from redis.asyncio.connection import PythonParser, UnixDomainSocketConnection
+from redis.exceptions import InvalidResponse
+from redis.utils import HIREDIS_AVAILABLE
+from tests.conftest import skip_if_server_version_lt
+
+from .compat import mock
+
+pytestmark = pytest.mark.asyncio
+
+
+@pytest.mark.onlynoncluster
+@pytest.mark.skipif(HIREDIS_AVAILABLE, reason="PythonParser only")
+async def test_invalid_response(create_redis):
+ r = await create_redis(single_connection_client=True)
+
+ raw = b"x"
+ readline_mock = mock.AsyncMock(return_value=raw)
+
+ parser: "PythonParser" = r.connection._parser
+ with mock.patch.object(parser._buffer, "readline", readline_mock):
+ with pytest.raises(InvalidResponse) as cm:
+ await parser.read_response()
+ assert str(cm.value) == f"Protocol Error: {raw!r}"
+
+
+@skip_if_server_version_lt("4.0.0")
+@pytest.mark.redismod
+@pytest.mark.onlynoncluster
+async def test_loading_external_modules(modclient):
+ def inner():
+ pass
+
+ modclient.load_external_module("myfuncname", inner)
+ assert getattr(modclient, "myfuncname") == inner
+ assert isinstance(getattr(modclient, "myfuncname"), types.FunctionType)
+
+ # and call it
+ from redis.commands import RedisModuleCommands
+
+ j = RedisModuleCommands.json
+ modclient.load_external_module("sometestfuncname", j)
+
+ # d = {'hello': 'world!'}
+ # mod = j(modclient)
+ # mod.set("fookey", ".", d)
+ # assert mod.get('fookey') == d
+
+
+@pytest.mark.onlynoncluster
+async def test_socket_param_regression(r):
+ """A regression test for issue #1060"""
+ conn = UnixDomainSocketConnection()
+ _ = await conn.disconnect() is True
+
+
+@pytest.mark.onlynoncluster
+async def test_can_run_concurrent_commands(r):
+ assert await r.ping() is True
+ assert all(await asyncio.gather(*(r.ping() for _ in range(10))))