Skip to content
This repository has been archived by the owner on Feb 21, 2023. It is now read-only.

Fix buffer is closed error when using PythonParser class #1213

Merged

Conversation

m-novikov
Copy link
Contributor

@m-novikov m-novikov commented Nov 20, 2021

What do these changes do?

Fix issue when the exception is raised on connection initialization in PythonParser
Add parametrization for both parsers to all tests using redis client to catch these errors in the future

Are there changes in behavior for the user?

No

Related issue number

#1212
#1114

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes
  • If you provide code modification, please add yourself to CONTRIBUTORS.txt
    • The format is <Name> <Surname>.
    • Please keep alphabetical order, the file is sorted by names.
  • Add a new news fragment into the CHANGES/ folder
    • name it <issue_id>.<type> (e.g. 588.bugfix)
    • if you don't have an issue_id change it to the pr id after creating the PR
    • ensure type is one of the following:
      • .feature: Signifying a new feature.
      • .bugfix: Signifying a bug fix.
      • .doc: Signifying a documentation improvement.
      • .removal: Signifying a deprecation or removal of public API.
      • .misc: A ticket has been closed, but it is not of interest to users.
    • Make sure to use full sentences with correct case and punctuation, for example:
      Fix issue with non-ascii contents in doctest text files.

@@ -373,7 +373,7 @@ def __init__(self, socket_read_size: int):
def on_connect(self, connection: "Connection"):
"""Called when the stream connects"""
self._stream = connection._reader
if self._buffer is None or self._stream is None:
if self._stream is None:
Copy link
Contributor Author

@m-novikov m-novikov Nov 20, 2021

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 here

Copy link
Collaborator

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

Copy link
Contributor Author

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 was self._buffer is None which always resulted in an exception. As it's not possible for it to be something other than None at this point.

@m-novikov m-novikov force-pushed the m-novikov-buffer-closed branch 2 times, most recently from f18236b to 2bcb685 Compare November 20, 2021 15:24
@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):
Copy link
Contributor Author

@m-novikov m-novikov Nov 20, 2021

Choose a reason for hiding this comment

The 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 AttributeError, because only a single connection client has a connection set. Ref #1114

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And it also didn't work on py =< 3.7

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And it also didn't work on py =< 3.7

We should probably drop Python 3.6 now anyways since it's EOL soon.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.
AsyncMock solves this problem.

@codecov
Copy link

codecov bot commented Nov 20, 2021

Codecov Report

Merging #1213 (b00926d) into master (33b2dbd) will increase coverage by 1.49%.
The diff coverage is 92.30%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1213      +/-   ##
==========================================
+ Coverage   89.21%   90.71%   +1.49%     
==========================================
  Files          21       21              
  Lines        6872     6872              
  Branches      794      793       -1     
==========================================
+ Hits         6131     6234     +103     
+ Misses        578      467     -111     
- Partials      163      171       +8     
Flag Coverage Δ
unit 90.62% <92.30%> (+1.49%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
aioredis/connection.py 77.67% <0.00%> (+11.28%) ⬆️
tests/conftest.py 92.25% <100.00%> (+0.05%) ⬆️
tests/test_connection.py 100.00% <100.00%> (+30.76%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 33b2dbd...b00926d. Read the comment docs.

Copy link
Collaborator

@Andrew-Chen-Wang Andrew-Chen-Wang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM. Change was in the mypy integration in #1101 Thanks!

@Andrew-Chen-Wang
Copy link
Collaborator

@m-novikov are the changes to the test files necessary though or is it possible to simply delete the if condition for self._buffer?

@m-novikov
Copy link
Contributor Author

m-novikov commented Nov 22, 2021

@Andrew-Chen-Wang changes in tests files are necessary to ensure that test pass also with PythonParser it seems like CI pipeline didn't actually run against PythonParser as HiredisParser was always available. At least from my understanding, this also closes #1114

@m-novikov
Copy link
Contributor Author

I am not actually sure if it worth to test all combinations, or only 3 of them should suffice. e.g. (hiredis pool and single) and python parser single

@Andrew-Chen-Wang Andrew-Chen-Wang linked an issue Nov 22, 2021 that may be closed by this pull request
@Andrew-Chen-Wang
Copy link
Collaborator

Andrew-Chen-Wang commented Nov 22, 2021

I agree that #1114 can be closed. I think having everything being tested is nice, though on CLI it might be annoying if you don't want to wait a full minute for the test suite to finish. Let me know if you disagree on that point. If not, I'll be merging this soon.

@m-novikov
Copy link
Contributor Author

m-novikov commented Nov 22, 2021

One option would be to add marks to params

diff --git a/tests/conftest.py b/tests/conftest.py
index 9d85205..ba82cfa 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -132,19 +132,25 @@ def skip_unless_arch_bits(arch_bits):
 
 @pytest.fixture(
     params=[
-        (True, PythonParser),
-        (False, PythonParser),
+        pytest.param((True, PythonParser), marks=[pytest.mark.python_parser]),
+        pytest.param((False, PythonParser), marks=[pytest.mark.python_parser]),
         pytest.param(
             (True, HiredisParser),
-            marks=pytest.mark.skipif(
-                not HIREDIS_AVAILABLE, reason="hiredis is not installed"
-            ),
+            marks=[
+                pytest.mark.skipif(
+                    not HIREDIS_AVAILABLE, reason="hiredis is not installed"
+                ),
+                pytest.mark.hiredis_parser,
+            ],
         ),
         pytest.param(
             (False, HiredisParser),
-            marks=pytest.mark.skipif(
-                not HIREDIS_AVAILABLE, reason="hiredis is not installed"
-            ),
+            marks=[
+                pytest.mark.skipif(
+                    not HIREDIS_AVAILABLE, reason="hiredis is not installed"
+                ),
+                pytest.mark.hiredis_parser,
+            ],
         ),
     ],
     ids=[

And then only marked tests can be run via pytest -v -m hiredis_parser
If this solution works for you and then I can add it to this PR or do a followup PR, maybe extending set of markers to the {single, pool, hiredis, python_parser}

@Andrew-Chen-Wang
Copy link
Collaborator

Let's merge this full test suite solution first; a separate PR for the marker solution would be great. I'll direct the other maintainers to decide on that.

@Andrew-Chen-Wang Andrew-Chen-Wang merged commit 2ba15fb into aio-libs-abandoned:master Nov 22, 2021
@Andrew-Chen-Wang
Copy link
Collaborator

Thanks again!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
2 participants