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 read bytes count #463

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion aiohttp/multipart.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def read_chunk(self, size=chunk_size):
'Content-Length required for chunked read'
chunk_size = min(size, self._length - self._read_bytes)
chunk = yield from self._content.read(chunk_size)
self._read_bytes += chunk_size
self._read_bytes += len(chunk)
if self._read_bytes == self._length:
self._at_eof = True
assert b'\r\n' == (yield from self._content.readline()), \
Expand Down
3 changes: 3 additions & 0 deletions tests/test_multipart.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import functools
import io
import os
import random
import unittest
import unittest.mock as mock
import zlib
Expand Down Expand Up @@ -67,6 +68,8 @@ def __init__(self, content):

@asyncio.coroutine
def read(self, size=None):
if size is not None:
size = random.randint(size // 2, size)
Copy link
Member

Choose a reason for hiding this comment

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

I dislike the test.
Let's assume we will break the code again.
Looking on random test failures I'll have no clue what's broken.

Copy link
Member

Choose a reason for hiding this comment

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

Agree. Better see separate test function that reproduces that behaviour.

return self.content.read(size)

@asyncio.coroutine
Expand Down