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