[Commented On] D12045: test-http-bad-server: refactor the reading logic to avoid early return

baymax (Baymax, Your Personal Patch-care Companion) phabricator at mercurial-scm.org
Mon Jan 24 18:17:08 UTC 2022


baymax added a comment.
baymax updated this revision to Diff 31869.


  ✅ refresh by Heptapod after a successful CI run (🐙 💚)

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D12045?vs=31748&id=31869

BRANCH
  default

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D12045/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D12045

AFFECTED FILES
  tests/testlib/badserverext.py

CHANGE DETAILS

diff --git a/tests/testlib/badserverext.py b/tests/testlib/badserverext.py
--- a/tests/testlib/badserverext.py
+++ b/tests/testlib/badserverext.py
@@ -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()
 



To: marmoute, #hg-reviewers, Alphare
Cc: mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-patches/attachments/20220124/83637193/attachment-0002.html>


More information about the Mercurial-patches mailing list