wireprotov2: pass ui into clientreactor and serverreactor
authorGregory Szorc <gregory.szorc@gmail.com>
Thu, 04 Oct 2018 17:17:57 -0700
changeset 40129 293835e0fff7
parent 40128 57782791b7e9
child 40130 5d44c4d1d516
wireprotov2: pass ui into clientreactor and serverreactor This will allow us to use config options to influence compression settings. Differential Revision: https://phab.mercurial-scm.org/D4919
mercurial/httppeer.py
mercurial/wireprotoframing.py
mercurial/wireprotov2server.py
tests/test-wireproto-clientreactor.py
tests/test-wireproto-serverreactor.py
--- a/mercurial/httppeer.py	Thu Oct 04 16:44:21 2018 -0700
+++ b/mercurial/httppeer.py	Thu Oct 04 17:17:57 2018 -0700
@@ -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,
--- a/mercurial/wireprotoframing.py	Thu Oct 04 16:44:21 2018 -0700
+++ b/mercurial/wireprotoframing.py	Thu Oct 04 17:17:57 2018 -0700
@@ -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
 
--- a/mercurial/wireprotov2server.py	Thu Oct 04 16:44:21 2018 -0700
+++ b/mercurial/wireprotov2server.py	Thu Oct 04 17:17:57 2018 -0700
@@ -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()
--- a/tests/test-wireproto-clientreactor.py	Thu Oct 04 16:44:21 2018 -0700
+++ b/tests/test-wireproto-clientreactor.py	Thu Oct 04 17:17:57 2018 -0700
@@ -4,6 +4,7 @@
 
 from mercurial import (
     error,
+    ui as uimod,
     wireprotoframing as framing,
 )
 from mercurial.utils import (
@@ -12,6 +13,8 @@
 
 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,7 +101,7 @@
             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')
@@ -102,7 +109,7 @@
                          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')
@@ -111,7 +118,7 @@
                          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']:
--- a/tests/test-wireproto-serverreactor.py	Thu Oct 04 16:44:21 2018 -0700
+++ b/tests/test-wireproto-serverreactor.py	Thu Oct 04 17:17:57 2018 -0700
@@ -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.