Mercurial > hg-stable
changeset 48636:3efc8644dd00
test-http-bad-server: refactor the reading logic to avoid early return
Our ultimate goal is to add another way to define the connection needs to be
closed. To do so, we need the "read" code to be more unified.
Differential Revision: https://phab.mercurial-scm.org/D12045
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Fri, 21 Jan 2022 11:15:56 +0100 |
parents | b060e305d79f |
children | e38776a4c2cb |
files | tests/testlib/badserverext.py |
diffstat | 1 files changed, 20 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/tests/testlib/badserverext.py Fri Jan 21 03:05:43 2022 +0100 +++ b/tests/testlib/badserverext.py Fri Jan 21 11:15:56 2022 +0100 @@ -157,32 +157,30 @@ bmethod = method.encode('ascii') func = getattr(orig, method) - # No read limit. Call original function. - if not remaining: - result = func(size) - obj._writelog( - b'%s(%d) -> (%d) %s' % (bmethod, size, len(result), result) - ) - return result + requested_size = size + actual_size = size + + if remaining: + if size < 0: + actual_size = remaining + else: + actual_size = min(remaining, requested_size) - origsize = size + result = func(actual_size) - if size < 0: - size = remaining + if remaining: + remaining -= len(result) + self.remaining_recv_bytes = remaining + + if requested_size == actual_size: + msg = b'%s(%d) -> (%d) %s' + msg %= (bmethod, requested_size, len(result), result) else: - size = min(remaining, size) - - result = func(size) - remaining -= len(result) + msg = b'%s(%d from %d) -> (%d) %s' + msg %= (bmethod, actual_size, requested_size, len(result), result) + obj._writelog(msg) - obj._writelog( - b'%s(%d from %d) -> (%d) %s' - % (bmethod, size, origsize, len(result), result) - ) - - self.remaining_recv_bytes = remaining - - if remaining <= 0: + if remaining is not None and remaining <= 0: obj._writelog(b'read limit reached; closing socket') obj._cond_close()