Skip to content
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

Fix issue with IndexError being raised by the StreamReader.iter_chunks() generator #2113

Merged
merged 4 commits into from Jul 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CONTRIBUTORS.txt
Expand Up @@ -104,6 +104,7 @@ Kirill Klenov
Kirill Malovitsa
Kyrylo Perevozchikov
Lars P. Søndergaard
Loïc Lajeanne
Louis-Philippe Huberdeau
Lu Gong
Lubomir Gelo
Expand Down
5 changes: 4 additions & 1 deletion aiohttp/streams.py
Expand Up @@ -326,7 +326,10 @@ def readchunk(self):
if not self._buffer and not self._eof:
yield from self._wait('readchunk')

return self._read_nowait_chunk(-1)
if self._buffer:
return self._read_nowait_chunk(-1)
else:
return b""

@asyncio.coroutine
def readexactly(self, n):
Expand Down
1 change: 1 addition & 0 deletions changes/2112.bugfix
@@ -0,0 +1 @@
Fix issue with IndexError being raised by the StreamReader.iter_chunks() generator.
15 changes: 13 additions & 2 deletions tests/test_streams.py
Expand Up @@ -547,7 +547,6 @@ def test_read_nowait_waiter(self):
self.assertRaises(RuntimeError, stream.read_nowait)

def test_readchunk(self):

stream = self._make_one()

def cb():
Expand All @@ -562,9 +561,21 @@ def cb():
data = self.loop.run_until_complete(stream.readchunk())
self.assertEqual(b'chunk2', data)

data = self.loop.run_until_complete(stream.read())
data = self.loop.run_until_complete(stream.readchunk())
self.assertEqual(b'', data)

def test_readchunk_wait_eof(self):
stream = self._make_one()

def cb():
yield from asyncio.sleep(0.1, loop=self.loop)
stream.feed_eof()

asyncio.Task(cb(), loop=self.loop)
data = self.loop.run_until_complete(stream.readchunk())
self.assertEqual(b"", data)
self.assertTrue(stream.is_eof())

def test___repr__(self):
stream = self._make_one()
self.assertEqual("<StreamReader>", repr(stream))
Expand Down