-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Make PythonParser resumable #2510
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dvora-h
merged 12 commits into
redis:master
from
mainframeindustries:kristjan/python-parser-state
Jan 5, 2023
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
622bee5
PythonParser is now resumable if _stream IO is interrupted
kristjanvalur 77560f7
Add test for parse resumability
kristjanvalur b87f4f0
Clear PythonParser state when connection or parsing errors occur.
kristjanvalur a87aedf
disable test for cluster mode.
kristjanvalur ab97a51
Perform "closed" check in a single place.
kristjanvalur 64b564c
Update tests
kristjanvalur 0f3fee7
Simplify code.
kristjanvalur 9289e0e
Remove reduntant test, EOF is detected inside _readline()
kristjanvalur 5c7c279
Make syncronous PythonParser restartable on error, same as HiredisParser
kristjanvalur 43eb806
Add CHANGES
kristjanvalur 789cc94
isort
kristjanvalur 56dc082
Move MockStream and MockSocket into their own files
kristjanvalur File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Various mocks for testing | ||
|
||
|
||
class MockSocket: | ||
""" | ||
A class simulating an readable socket, optionally raising a | ||
special exception every other read. | ||
""" | ||
|
||
class TestError(BaseException): | ||
pass | ||
|
||
def __init__(self, data, interrupt_every=0): | ||
self.data = data | ||
self.counter = 0 | ||
self.pos = 0 | ||
self.interrupt_every = interrupt_every | ||
|
||
def tick(self): | ||
self.counter += 1 | ||
if not self.interrupt_every: | ||
return | ||
if (self.counter % self.interrupt_every) == 0: | ||
raise self.TestError() | ||
|
||
def recv(self, bufsize): | ||
self.tick() | ||
bufsize = min(5, bufsize) # truncate the read size | ||
result = self.data[self.pos : self.pos + bufsize] | ||
self.pos += len(result) | ||
return result | ||
|
||
def recv_into(self, buffer, nbytes=0, flags=0): | ||
self.tick() | ||
if nbytes == 0: | ||
nbytes = len(buffer) | ||
nbytes = min(5, nbytes) # truncate the read size | ||
result = self.data[self.pos : self.pos + nbytes] | ||
self.pos += len(result) | ||
buffer[: len(result)] = result | ||
return len(result) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import asyncio | ||
|
||
# Helper Mocking classes for the tests. | ||
|
||
|
||
class MockStream: | ||
""" | ||
A class simulating an asyncio input buffer, optionally raising a | ||
special exception every other read. | ||
""" | ||
|
||
class TestError(BaseException): | ||
pass | ||
|
||
def __init__(self, data, interrupt_every=0): | ||
self.data = data | ||
self.counter = 0 | ||
self.pos = 0 | ||
self.interrupt_every = interrupt_every | ||
|
||
def tick(self): | ||
self.counter += 1 | ||
if not self.interrupt_every: | ||
return | ||
if (self.counter % self.interrupt_every) == 0: | ||
raise self.TestError() | ||
|
||
async def read(self, want): | ||
self.tick() | ||
want = 5 | ||
result = self.data[self.pos : self.pos + want] | ||
self.pos += len(result) | ||
return result | ||
|
||
async def readline(self): | ||
self.tick() | ||
find = self.data.find(b"\n", self.pos) | ||
if find >= 0: | ||
result = self.data[self.pos : find + 1] | ||
else: | ||
result = self.data[self.pos :] | ||
self.pos += len(result) | ||
return result | ||
|
||
async def readexactly(self, length): | ||
self.tick() | ||
result = self.data[self.pos : self.pos + length] | ||
if len(result) < length: | ||
raise asyncio.IncompleteReadError(result, None) | ||
self.pos += len(result) | ||
return result |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.