D4919: wireprotov2: pass ui into clientreactor and serverreactor

indygreg (Gregory Szorc) phabricator at mercurial-scm.org
Tue Oct 9 00:31:00 UTC 2018


indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  This will allow us to use config options to influence compression
  settings.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/httppeer.py
  mercurial/wireprotoframing.py
  mercurial/wireprotov2server.py
  tests/test-wireproto-clientreactor.py
  tests/test-wireproto-serverreactor.py

CHANGE DETAILS

diff --git a/tests/test-wireproto-serverreactor.py b/tests/test-wireproto-serverreactor.py
--- a/tests/test-wireproto-serverreactor.py
+++ b/tests/test-wireproto-serverreactor.py
@@ -6,6 +6,7 @@
     cbor,
 )
 from mercurial import (
+    ui as uimod,
     util,
     wireprotoframing as framing,
 )
@@ -18,7 +19,8 @@
 OK = cbor.dumps({b'status': b'ok'})
 
 def makereactor(deferoutput=False):
-    return framing.serverreactor(deferoutput=deferoutput)
+    ui = uimod.ui()
+    return framing.serverreactor(ui, deferoutput=deferoutput)
 
 def sendframes(reactor, gen):
     """Send a generator of frame bytearray to a reactor.
diff --git a/tests/test-wireproto-clientreactor.py b/tests/test-wireproto-clientreactor.py
--- a/tests/test-wireproto-clientreactor.py
+++ b/tests/test-wireproto-clientreactor.py
@@ -4,14 +4,17 @@
 
 from mercurial import (
     error,
+    ui as uimod,
     wireprotoframing as framing,
 )
 from mercurial.utils import (
     cborutil,
 )
 
 ffs = framing.makeframefromhumanstring
 
+globalui = uimod.ui()
+
 def sendframe(reactor, frame):
     """Send a frame bytearray to a reactor."""
     header = framing.parseheader(frame)
@@ -35,7 +38,9 @@
             unittest.TestCase.assertRaisesRegexp)
 
     def testbasic(self):
-        reactor = framing.clientreactor(hasmultiplesend=False, buffersends=True)
+        reactor = framing.clientreactor(globalui,
+                                        hasmultiplesend=False,
+                                        buffersends=True)
 
         request, action, meta = reactor.callcommand(b'foo', {})
         self.assertEqual(request.state, b'pending')
@@ -60,7 +65,9 @@
 class NoBufferTests(unittest.TestCase):
     """A reactor without send buffering sends requests immediately."""
     def testbasic(self):
-        reactor = framing.clientreactor(hasmultiplesend=True, buffersends=False)
+        reactor = framing.clientreactor(globalui,
+                                        hasmultiplesend=True,
+                                        buffersends=False)
 
         request, action, meta = reactor.callcommand(b'command1', {})
         self.assertEqual(request.requestid, 1)
@@ -94,24 +101,24 @@
             unittest.TestCase.assertRaisesRegexp)
 
     def testoddstream(self):
-        reactor = framing.clientreactor()
+        reactor = framing.clientreactor(globalui)
 
         action, meta = sendframe(reactor, ffs(b'1 1 0 1 0 foo'))
         self.assertEqual(action, b'error')
         self.assertEqual(meta[b'message'],
                          b'received frame with odd numbered stream ID: 1')
 
     def testunknownstream(self):
-        reactor = framing.clientreactor()
+        reactor = framing.clientreactor(globalui)
 
         action, meta = sendframe(reactor, ffs(b'1 0 0 1 0 foo'))
         self.assertEqual(action, b'error')
         self.assertEqual(meta[b'message'],
                          b'received frame on unknown stream without beginning '
                          b'of stream flag set')
 
     def testunhandledframetype(self):
-        reactor = framing.clientreactor(buffersends=False)
+        reactor = framing.clientreactor(globalui, buffersends=False)
 
         request, action, meta = reactor.callcommand(b'foo', {})
         for frame in meta[b'framegen']:
@@ -123,7 +130,7 @@
 
 class StreamTests(unittest.TestCase):
     def testmultipleresponseframes(self):
-        reactor = framing.clientreactor(buffersends=False)
+        reactor = framing.clientreactor(globalui, buffersends=False)
 
         request, action, meta = reactor.callcommand(b'foo', {})
 
@@ -144,7 +151,7 @@
 
 class RedirectTests(unittest.TestCase):
     def testredirect(self):
-        reactor = framing.clientreactor(buffersends=False)
+        reactor = framing.clientreactor(globalui, buffersends=False)
 
         redirect = {
             b'targets': [b'a', b'b'],
@@ -167,7 +174,7 @@
 
 class StreamSettingsTests(unittest.TestCase):
     def testnoflags(self):
-        reactor = framing.clientreactor(buffersends=False)
+        reactor = framing.clientreactor(globalui, buffersends=False)
 
         request, action, meta = reactor.callcommand(b'foo', {})
         for f in meta[b'framegen']:
@@ -183,7 +190,7 @@
         })
 
     def testconflictflags(self):
-        reactor = framing.clientreactor(buffersends=False)
+        reactor = framing.clientreactor(globalui, buffersends=False)
 
         request, action, meta = reactor.callcommand(b'foo', {})
         for f in meta[b'framegen']:
@@ -199,7 +206,7 @@
         })
 
     def testemptypayload(self):
-        reactor = framing.clientreactor(buffersends=False)
+        reactor = framing.clientreactor(globalui, buffersends=False)
 
         request, action, meta = reactor.callcommand(b'foo', {})
         for f in meta[b'framegen']:
@@ -215,7 +222,7 @@
         })
 
     def testbadcbor(self):
-        reactor = framing.clientreactor(buffersends=False)
+        reactor = framing.clientreactor(globalui, buffersends=False)
 
         request, action, meta = reactor.callcommand(b'foo', {})
         for f in meta[b'framegen']:
@@ -227,7 +234,7 @@
         self.assertEqual(action, b'error')
 
     def testsingleobject(self):
-        reactor = framing.clientreactor(buffersends=False)
+        reactor = framing.clientreactor(globalui, buffersends=False)
 
         request, action, meta = reactor.callcommand(b'foo', {})
         for f in meta[b'framegen']:
@@ -240,7 +247,7 @@
         self.assertEqual(meta, {})
 
     def testmultipleobjects(self):
-        reactor = framing.clientreactor(buffersends=False)
+        reactor = framing.clientreactor(globalui, buffersends=False)
 
         request, action, meta = reactor.callcommand(b'foo', {})
         for f in meta[b'framegen']:
@@ -258,7 +265,7 @@
         self.assertEqual(meta, {})
 
     def testmultipleframes(self):
-        reactor = framing.clientreactor(buffersends=False)
+        reactor = framing.clientreactor(globalui, buffersends=False)
 
         request, action, meta = reactor.callcommand(b'foo', {})
         for f in meta[b'framegen']:
diff --git a/mercurial/wireprotov2server.py b/mercurial/wireprotov2server.py
--- a/mercurial/wireprotov2server.py
+++ b/mercurial/wireprotov2server.py
@@ -156,7 +156,7 @@
 
     # We assume we have a unified framing protocol request body.
 
-    reactor = wireprotoframing.serverreactor()
+    reactor = wireprotoframing.serverreactor(ui)
     states = []
 
     while True:
@@ -191,7 +191,7 @@
     # TODO Some HTTP clients are full duplex and can receive data before
     # the entire request is transmitted. Figure out a way to indicate support
     # for that so we can opt into full duplex mode.
-    reactor = wireprotoframing.serverreactor(deferoutput=True)
+    reactor = wireprotoframing.serverreactor(ui, deferoutput=True)
     seencommand = False
 
     outstream = reactor.makeoutputstream()
diff --git a/mercurial/wireprotoframing.py b/mercurial/wireprotoframing.py
--- a/mercurial/wireprotoframing.py
+++ b/mercurial/wireprotoframing.py
@@ -750,7 +750,7 @@
     between who responds to what.
     """
 
-    def __init__(self, deferoutput=False):
+    def __init__(self, ui, deferoutput=False):
         """Construct a new server reactor.
 
         ``deferoutput`` can be used to indicate that no output frames should be
@@ -760,6 +760,7 @@
         send those frames. This is useful for half-duplex transports where the
         sender cannot receive until all data has been transmitted.
         """
+        self._ui = ui
         self._deferoutput = deferoutput
         self._state = 'initial'
         self._nextoutgoingstreamid = 2
@@ -1351,7 +1352,7 @@
        is expected to follow or we're at the end of the response stream,
        respectively.
     """
-    def __init__(self, hasmultiplesend=False, buffersends=True):
+    def __init__(self, ui, hasmultiplesend=False, buffersends=True):
         """Create a new instance.
 
         ``hasmultiplesend`` indicates whether multiple sends are supported
@@ -1362,6 +1363,7 @@
         ``buffercommands`` indicates whether sends should be buffered until the
         last request has been issued.
         """
+        self._ui = ui
         self._hasmultiplesend = hasmultiplesend
         self._buffersends = buffersends
 
diff --git a/mercurial/httppeer.py b/mercurial/httppeer.py
--- a/mercurial/httppeer.py
+++ b/mercurial/httppeer.py
@@ -514,7 +514,8 @@
 
 def sendv2request(ui, opener, requestbuilder, apiurl, permission, requests,
                   redirect):
-    reactor = wireprotoframing.clientreactor(hasmultiplesend=False,
+    reactor = wireprotoframing.clientreactor(ui,
+                                             hasmultiplesend=False,
                                              buffersends=True)
 
     handler = wireprotov2peer.clienthandler(ui, reactor,



To: indygreg, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list