-
Notifications
You must be signed in to change notification settings - Fork 335
Fix buffer is closed error when using PythonParser class #1213
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fix buffer is closed error when using PythonParser class |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,24 @@ | ||
import asyncio | ||
from typing import TYPE_CHECKING | ||
from unittest import mock | ||
|
||
import pytest | ||
|
||
from aioredis.connection import UnixDomainSocketConnection | ||
from aioredis.connection import PythonParser, UnixDomainSocketConnection | ||
from aioredis.exceptions import InvalidResponse | ||
from aioredis.utils import HIREDIS_AVAILABLE | ||
|
||
if TYPE_CHECKING: | ||
from aioredis.connection import PythonParser | ||
from .compat import mock | ||
|
||
|
||
@pytest.mark.skipif(HIREDIS_AVAILABLE, reason="PythonParser only") | ||
@pytest.mark.asyncio | ||
async def test_invalid_response(r): | ||
@pytest.mark.parametrize("create_redis", [(True, PythonParser)], indirect=True) | ||
async def test_invalid_response(create_redis): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test seems like it wasn't run for some time, as in the case of connection pool it will fail with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And it also didn't work on py =< 3.7 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
We should probably drop Python 3.6 now anyways since it's EOL soon. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But for 3.7 it's still a problem and pypy seems to be unhappy about this test also. |
||
r = await create_redis() | ||
|
||
raw = b"x" | ||
readline_mock = mock.AsyncMock(return_value=raw) | ||
|
||
parser: "PythonParser" = r.connection._parser | ||
with mock.patch.object(parser._buffer, "readline", return_value=raw): | ||
with mock.patch.object(parser._buffer, "readline", readline_mock): | ||
with pytest.raises(InvalidResponse) as cm: | ||
await parser.read_response() | ||
assert str(cm.value) == "Protocol Error: %r" % raw | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not too sure what was the original intent behind this line, buffer only initialized after so it only can be
None
hereThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i believe we've had unexpected behavior here before, so keeping that there would be nice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self._stream is None
check is kept and test seems to be passing with it, The problem wasself._buffer is None
which always resulted in an exception. As it's not possible for it to be something other thanNone
at this point.