##// END OF EJS Templates
wireprotov2: pass ui into clientreactor and serverreactor...
Gregory Szorc -
r40165:293835e0 default
parent child Browse files
Show More
@@ -514,7 +514,8 b' class httppeer(wireprotov1peer.wirepeer)'
514
514
515 def sendv2request(ui, opener, requestbuilder, apiurl, permission, requests,
515 def sendv2request(ui, opener, requestbuilder, apiurl, permission, requests,
516 redirect):
516 redirect):
517 reactor = wireprotoframing.clientreactor(hasmultiplesend=False,
517 reactor = wireprotoframing.clientreactor(ui,
518 hasmultiplesend=False,
518 buffersends=True)
519 buffersends=True)
519
520
520 handler = wireprotov2peer.clienthandler(ui, reactor,
521 handler = wireprotov2peer.clienthandler(ui, reactor,
@@ -750,7 +750,7 b' class serverreactor(object):'
750 between who responds to what.
750 between who responds to what.
751 """
751 """
752
752
753 def __init__(self, deferoutput=False):
753 def __init__(self, ui, deferoutput=False):
754 """Construct a new server reactor.
754 """Construct a new server reactor.
755
755
756 ``deferoutput`` can be used to indicate that no output frames should be
756 ``deferoutput`` can be used to indicate that no output frames should be
@@ -760,6 +760,7 b' class serverreactor(object):'
760 send those frames. This is useful for half-duplex transports where the
760 send those frames. This is useful for half-duplex transports where the
761 sender cannot receive until all data has been transmitted.
761 sender cannot receive until all data has been transmitted.
762 """
762 """
763 self._ui = ui
763 self._deferoutput = deferoutput
764 self._deferoutput = deferoutput
764 self._state = 'initial'
765 self._state = 'initial'
765 self._nextoutgoingstreamid = 2
766 self._nextoutgoingstreamid = 2
@@ -1351,7 +1352,7 b' class clientreactor(object):'
1351 is expected to follow or we're at the end of the response stream,
1352 is expected to follow or we're at the end of the response stream,
1352 respectively.
1353 respectively.
1353 """
1354 """
1354 def __init__(self, hasmultiplesend=False, buffersends=True):
1355 def __init__(self, ui, hasmultiplesend=False, buffersends=True):
1355 """Create a new instance.
1356 """Create a new instance.
1356
1357
1357 ``hasmultiplesend`` indicates whether multiple sends are supported
1358 ``hasmultiplesend`` indicates whether multiple sends are supported
@@ -1362,6 +1363,7 b' class clientreactor(object):'
1362 ``buffercommands`` indicates whether sends should be buffered until the
1363 ``buffercommands`` indicates whether sends should be buffered until the
1363 last request has been issued.
1364 last request has been issued.
1364 """
1365 """
1366 self._ui = ui
1365 self._hasmultiplesend = hasmultiplesend
1367 self._hasmultiplesend = hasmultiplesend
1366 self._buffersends = buffersends
1368 self._buffersends = buffersends
1367
1369
@@ -156,7 +156,7 b' def _processhttpv2reflectrequest(ui, rep'
156
156
157 # We assume we have a unified framing protocol request body.
157 # We assume we have a unified framing protocol request body.
158
158
159 reactor = wireprotoframing.serverreactor()
159 reactor = wireprotoframing.serverreactor(ui)
160 states = []
160 states = []
161
161
162 while True:
162 while True:
@@ -191,7 +191,7 b' def _processhttpv2request(ui, repo, req,'
191 # TODO Some HTTP clients are full duplex and can receive data before
191 # TODO Some HTTP clients are full duplex and can receive data before
192 # the entire request is transmitted. Figure out a way to indicate support
192 # the entire request is transmitted. Figure out a way to indicate support
193 # for that so we can opt into full duplex mode.
193 # for that so we can opt into full duplex mode.
194 reactor = wireprotoframing.serverreactor(deferoutput=True)
194 reactor = wireprotoframing.serverreactor(ui, deferoutput=True)
195 seencommand = False
195 seencommand = False
196
196
197 outstream = reactor.makeoutputstream()
197 outstream = reactor.makeoutputstream()
@@ -4,6 +4,7 b' import unittest'
4
4
5 from mercurial import (
5 from mercurial import (
6 error,
6 error,
7 ui as uimod,
7 wireprotoframing as framing,
8 wireprotoframing as framing,
8 )
9 )
9 from mercurial.utils import (
10 from mercurial.utils import (
@@ -12,6 +13,8 b' from mercurial.utils import ('
12
13
13 ffs = framing.makeframefromhumanstring
14 ffs = framing.makeframefromhumanstring
14
15
16 globalui = uimod.ui()
17
15 def sendframe(reactor, frame):
18 def sendframe(reactor, frame):
16 """Send a frame bytearray to a reactor."""
19 """Send a frame bytearray to a reactor."""
17 header = framing.parseheader(frame)
20 header = framing.parseheader(frame)
@@ -35,7 +38,9 b' class SingleSendTests(unittest.TestCase)'
35 unittest.TestCase.assertRaisesRegexp)
38 unittest.TestCase.assertRaisesRegexp)
36
39
37 def testbasic(self):
40 def testbasic(self):
38 reactor = framing.clientreactor(hasmultiplesend=False, buffersends=True)
41 reactor = framing.clientreactor(globalui,
42 hasmultiplesend=False,
43 buffersends=True)
39
44
40 request, action, meta = reactor.callcommand(b'foo', {})
45 request, action, meta = reactor.callcommand(b'foo', {})
41 self.assertEqual(request.state, b'pending')
46 self.assertEqual(request.state, b'pending')
@@ -60,7 +65,9 b' class SingleSendTests(unittest.TestCase)'
60 class NoBufferTests(unittest.TestCase):
65 class NoBufferTests(unittest.TestCase):
61 """A reactor without send buffering sends requests immediately."""
66 """A reactor without send buffering sends requests immediately."""
62 def testbasic(self):
67 def testbasic(self):
63 reactor = framing.clientreactor(hasmultiplesend=True, buffersends=False)
68 reactor = framing.clientreactor(globalui,
69 hasmultiplesend=True,
70 buffersends=False)
64
71
65 request, action, meta = reactor.callcommand(b'command1', {})
72 request, action, meta = reactor.callcommand(b'command1', {})
66 self.assertEqual(request.requestid, 1)
73 self.assertEqual(request.requestid, 1)
@@ -94,7 +101,7 b' class BadFrameRecvTests(unittest.TestCas'
94 unittest.TestCase.assertRaisesRegexp)
101 unittest.TestCase.assertRaisesRegexp)
95
102
96 def testoddstream(self):
103 def testoddstream(self):
97 reactor = framing.clientreactor()
104 reactor = framing.clientreactor(globalui)
98
105
99 action, meta = sendframe(reactor, ffs(b'1 1 0 1 0 foo'))
106 action, meta = sendframe(reactor, ffs(b'1 1 0 1 0 foo'))
100 self.assertEqual(action, b'error')
107 self.assertEqual(action, b'error')
@@ -102,7 +109,7 b' class BadFrameRecvTests(unittest.TestCas'
102 b'received frame with odd numbered stream ID: 1')
109 b'received frame with odd numbered stream ID: 1')
103
110
104 def testunknownstream(self):
111 def testunknownstream(self):
105 reactor = framing.clientreactor()
112 reactor = framing.clientreactor(globalui)
106
113
107 action, meta = sendframe(reactor, ffs(b'1 0 0 1 0 foo'))
114 action, meta = sendframe(reactor, ffs(b'1 0 0 1 0 foo'))
108 self.assertEqual(action, b'error')
115 self.assertEqual(action, b'error')
@@ -111,7 +118,7 b' class BadFrameRecvTests(unittest.TestCas'
111 b'of stream flag set')
118 b'of stream flag set')
112
119
113 def testunhandledframetype(self):
120 def testunhandledframetype(self):
114 reactor = framing.clientreactor(buffersends=False)
121 reactor = framing.clientreactor(globalui, buffersends=False)
115
122
116 request, action, meta = reactor.callcommand(b'foo', {})
123 request, action, meta = reactor.callcommand(b'foo', {})
117 for frame in meta[b'framegen']:
124 for frame in meta[b'framegen']:
@@ -123,7 +130,7 b' class BadFrameRecvTests(unittest.TestCas'
123
130
124 class StreamTests(unittest.TestCase):
131 class StreamTests(unittest.TestCase):
125 def testmultipleresponseframes(self):
132 def testmultipleresponseframes(self):
126 reactor = framing.clientreactor(buffersends=False)
133 reactor = framing.clientreactor(globalui, buffersends=False)
127
134
128 request, action, meta = reactor.callcommand(b'foo', {})
135 request, action, meta = reactor.callcommand(b'foo', {})
129
136
@@ -144,7 +151,7 b' class StreamTests(unittest.TestCase):'
144
151
145 class RedirectTests(unittest.TestCase):
152 class RedirectTests(unittest.TestCase):
146 def testredirect(self):
153 def testredirect(self):
147 reactor = framing.clientreactor(buffersends=False)
154 reactor = framing.clientreactor(globalui, buffersends=False)
148
155
149 redirect = {
156 redirect = {
150 b'targets': [b'a', b'b'],
157 b'targets': [b'a', b'b'],
@@ -167,7 +174,7 b' class RedirectTests(unittest.TestCase):'
167
174
168 class StreamSettingsTests(unittest.TestCase):
175 class StreamSettingsTests(unittest.TestCase):
169 def testnoflags(self):
176 def testnoflags(self):
170 reactor = framing.clientreactor(buffersends=False)
177 reactor = framing.clientreactor(globalui, buffersends=False)
171
178
172 request, action, meta = reactor.callcommand(b'foo', {})
179 request, action, meta = reactor.callcommand(b'foo', {})
173 for f in meta[b'framegen']:
180 for f in meta[b'framegen']:
@@ -183,7 +190,7 b' class StreamSettingsTests(unittest.TestC'
183 })
190 })
184
191
185 def testconflictflags(self):
192 def testconflictflags(self):
186 reactor = framing.clientreactor(buffersends=False)
193 reactor = framing.clientreactor(globalui, buffersends=False)
187
194
188 request, action, meta = reactor.callcommand(b'foo', {})
195 request, action, meta = reactor.callcommand(b'foo', {})
189 for f in meta[b'framegen']:
196 for f in meta[b'framegen']:
@@ -199,7 +206,7 b' class StreamSettingsTests(unittest.TestC'
199 })
206 })
200
207
201 def testemptypayload(self):
208 def testemptypayload(self):
202 reactor = framing.clientreactor(buffersends=False)
209 reactor = framing.clientreactor(globalui, buffersends=False)
203
210
204 request, action, meta = reactor.callcommand(b'foo', {})
211 request, action, meta = reactor.callcommand(b'foo', {})
205 for f in meta[b'framegen']:
212 for f in meta[b'framegen']:
@@ -215,7 +222,7 b' class StreamSettingsTests(unittest.TestC'
215 })
222 })
216
223
217 def testbadcbor(self):
224 def testbadcbor(self):
218 reactor = framing.clientreactor(buffersends=False)
225 reactor = framing.clientreactor(globalui, buffersends=False)
219
226
220 request, action, meta = reactor.callcommand(b'foo', {})
227 request, action, meta = reactor.callcommand(b'foo', {})
221 for f in meta[b'framegen']:
228 for f in meta[b'framegen']:
@@ -227,7 +234,7 b' class StreamSettingsTests(unittest.TestC'
227 self.assertEqual(action, b'error')
234 self.assertEqual(action, b'error')
228
235
229 def testsingleobject(self):
236 def testsingleobject(self):
230 reactor = framing.clientreactor(buffersends=False)
237 reactor = framing.clientreactor(globalui, buffersends=False)
231
238
232 request, action, meta = reactor.callcommand(b'foo', {})
239 request, action, meta = reactor.callcommand(b'foo', {})
233 for f in meta[b'framegen']:
240 for f in meta[b'framegen']:
@@ -240,7 +247,7 b' class StreamSettingsTests(unittest.TestC'
240 self.assertEqual(meta, {})
247 self.assertEqual(meta, {})
241
248
242 def testmultipleobjects(self):
249 def testmultipleobjects(self):
243 reactor = framing.clientreactor(buffersends=False)
250 reactor = framing.clientreactor(globalui, buffersends=False)
244
251
245 request, action, meta = reactor.callcommand(b'foo', {})
252 request, action, meta = reactor.callcommand(b'foo', {})
246 for f in meta[b'framegen']:
253 for f in meta[b'framegen']:
@@ -258,7 +265,7 b' class StreamSettingsTests(unittest.TestC'
258 self.assertEqual(meta, {})
265 self.assertEqual(meta, {})
259
266
260 def testmultipleframes(self):
267 def testmultipleframes(self):
261 reactor = framing.clientreactor(buffersends=False)
268 reactor = framing.clientreactor(globalui, buffersends=False)
262
269
263 request, action, meta = reactor.callcommand(b'foo', {})
270 request, action, meta = reactor.callcommand(b'foo', {})
264 for f in meta[b'framegen']:
271 for f in meta[b'framegen']:
@@ -6,6 +6,7 b' from mercurial.thirdparty import ('
6 cbor,
6 cbor,
7 )
7 )
8 from mercurial import (
8 from mercurial import (
9 ui as uimod,
9 util,
10 util,
10 wireprotoframing as framing,
11 wireprotoframing as framing,
11 )
12 )
@@ -18,7 +19,8 b' ffs = framing.makeframefromhumanstring'
18 OK = cbor.dumps({b'status': b'ok'})
19 OK = cbor.dumps({b'status': b'ok'})
19
20
20 def makereactor(deferoutput=False):
21 def makereactor(deferoutput=False):
21 return framing.serverreactor(deferoutput=deferoutput)
22 ui = uimod.ui()
23 return framing.serverreactor(ui, deferoutput=deferoutput)
22
24
23 def sendframes(reactor, gen):
25 def sendframes(reactor, gen):
24 """Send a generator of frame bytearray to a reactor.
26 """Send a generator of frame bytearray to a reactor.
General Comments 0
You need to be logged in to leave comments. Login now