summaryrefslogtreecommitdiff
path: root/tests/test_asyncio/test_commands.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_asyncio/test_commands.py')
-rw-r--r--tests/test_asyncio/test_commands.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/test_asyncio/test_commands.py b/tests/test_asyncio/test_commands.py
index 409934c..ac3537d 100644
--- a/tests/test_asyncio/test_commands.py
+++ b/tests/test_asyncio/test_commands.py
@@ -1,9 +1,11 @@
"""
Tests async overrides of commands from their mixins
"""
+import asyncio
import binascii
import datetime
import re
+import sys
from string import ascii_letters
import pytest
@@ -18,6 +20,11 @@ from tests.conftest import (
skip_unless_arch_bits,
)
+if sys.version_info >= (3, 11, 3):
+ from asyncio import timeout as async_timeout
+else:
+ from async_timeout import timeout as async_timeout
+
REDIS_6_VERSION = "5.9.0"
@@ -3008,6 +3015,37 @@ class TestRedisCommands:
for x in await r.module_list():
assert isinstance(x, dict)
+ @pytest.mark.onlynoncluster
+ async def test_interrupted_command(self, r: redis.Redis):
+ """
+ Regression test for issue #1128: An Un-handled BaseException
+ will leave the socket with un-read response to a previous
+ command.
+ """
+ ready = asyncio.Event()
+
+ async def helper():
+ with pytest.raises(asyncio.CancelledError):
+ # blocking pop
+ ready.set()
+ await r.brpop(["nonexist"])
+ # If the following is not done, further Timout operations will fail,
+ # because the timeout won't catch its Cancelled Error if the task
+ # has a pending cancel. Python documentation probably should reflect this.
+ if sys.version_info >= (3, 11):
+ asyncio.current_task().uncancel()
+ # if all is well, we can continue. The following should not hang.
+ await r.set("status", "down")
+
+ task = asyncio.create_task(helper())
+ await ready.wait()
+ await asyncio.sleep(0.01)
+ # the task is now sleeping, lets send it an exception
+ task.cancel()
+ # If all is well, the task should finish right away, otherwise fail with Timeout
+ async with async_timeout(0.1):
+ await task
+
@pytest.mark.onlynoncluster
class TestBinarySave: