comparison tests/test-wireproto-serverreactor.py @ 40025:b099e6032f38

wireprotov2: server support for sending content redirects A "content redirect" can be sent in place of inline response content. In terms of code, we model a content redirect as a special type of response object holding the attributes describing that redirect. Sending a content redirect thus becomes as simple as the object emission layer sending an instance of that type. A cacher using externally-addressable content storage could replace the outgoing object stream with an object advertising its location. The bulk of the code in this commit is teaching the output layer which handles the object stream to recognize alternate location objects. The rules are that if an alternate location object is present, it must be the first and only object in the object stream. Otherwise the server emits an error. Differential Revision: https://phab.mercurial-scm.org/D4777
author Gregory Szorc <gregory.szorc@gmail.com>
date Wed, 26 Sep 2018 18:07:55 -0700
parents 0c184ca594bb
children 327d40b94bed
comparison
equal deleted inserted replaced
40024:86b22a4cfab1 40025:b099e6032f38
67 self.assertaction(results[0], b'runcommand') 67 self.assertaction(results[0], b'runcommand')
68 self.assertEqual(results[0][1], { 68 self.assertEqual(results[0][1], {
69 b'requestid': 1, 69 b'requestid': 1,
70 b'command': b'mycommand', 70 b'command': b'mycommand',
71 b'args': {}, 71 b'args': {},
72 b'redirect': None,
72 b'data': None, 73 b'data': None,
73 }) 74 })
74 75
75 result = reactor.oninputeof() 76 result = reactor.oninputeof()
76 self.assertaction(result, b'noop') 77 self.assertaction(result, b'noop')
84 self.assertaction(results[0], b'runcommand') 85 self.assertaction(results[0], b'runcommand')
85 self.assertEqual(results[0][1], { 86 self.assertEqual(results[0][1], {
86 b'requestid': 41, 87 b'requestid': 41,
87 b'command': b'mycommand', 88 b'command': b'mycommand',
88 b'args': {b'foo': b'bar'}, 89 b'args': {b'foo': b'bar'},
90 b'redirect': None,
89 b'data': None, 91 b'data': None,
90 }) 92 })
91 93
92 def testmultiarguments(self): 94 def testmultiarguments(self):
93 reactor = makereactor() 95 reactor = makereactor()
98 self.assertaction(results[0], b'runcommand') 100 self.assertaction(results[0], b'runcommand')
99 self.assertEqual(results[0][1], { 101 self.assertEqual(results[0][1], {
100 b'requestid': 1, 102 b'requestid': 1,
101 b'command': b'mycommand', 103 b'command': b'mycommand',
102 b'args': {b'foo': b'bar', b'biz': b'baz'}, 104 b'args': {b'foo': b'bar', b'biz': b'baz'},
105 b'redirect': None,
103 b'data': None, 106 b'data': None,
104 }) 107 })
105 108
106 def testsimplecommanddata(self): 109 def testsimplecommanddata(self):
107 reactor = makereactor() 110 reactor = makereactor()
113 self.assertaction(results[1], b'runcommand') 116 self.assertaction(results[1], b'runcommand')
114 self.assertEqual(results[1][1], { 117 self.assertEqual(results[1][1], {
115 b'requestid': 1, 118 b'requestid': 1,
116 b'command': b'mycommand', 119 b'command': b'mycommand',
117 b'args': {}, 120 b'args': {},
121 b'redirect': None,
118 b'data': b'data!', 122 b'data': b'data!',
119 }) 123 })
120 124
121 def testmultipledataframes(self): 125 def testmultipledataframes(self):
122 frames = [ 126 frames = [
135 self.assertaction(results[3], b'runcommand') 139 self.assertaction(results[3], b'runcommand')
136 self.assertEqual(results[3][1], { 140 self.assertEqual(results[3][1], {
137 b'requestid': 1, 141 b'requestid': 1,
138 b'command': b'mycommand', 142 b'command': b'mycommand',
139 b'args': {}, 143 b'args': {},
144 b'redirect': None,
140 b'data': b'data1data2data3', 145 b'data': b'data1data2data3',
141 }) 146 })
142 147
143 def testargumentanddata(self): 148 def testargumentanddata(self):
144 frames = [ 149 frames = [
158 b'command': b'command', 163 b'command': b'command',
159 b'args': { 164 b'args': {
160 b'key': b'val', 165 b'key': b'val',
161 b'foo': b'bar', 166 b'foo': b'bar',
162 }, 167 },
168 b'redirect': None,
163 b'data': b'value1value2', 169 b'data': b'value1value2',
164 }) 170 })
165 171
166 def testnewandcontinuation(self): 172 def testnewandcontinuation(self):
167 result = self._sendsingleframe(makereactor(), 173 result = self._sendsingleframe(makereactor(),
233 self.assertaction(results[i], b'runcommand') 239 self.assertaction(results[i], b'runcommand')
234 self.assertEqual(results[i][1], { 240 self.assertEqual(results[i][1], {
235 b'requestid': 1, 241 b'requestid': 1,
236 b'command': b'command', 242 b'command': b'command',
237 b'args': {}, 243 b'args': {},
244 b'redirect': None,
238 b'data': None, 245 b'data': None,
239 }) 246 })
240 247
241 def testconflictingrequestid(self): 248 def testconflictingrequestid(self):
242 """Request ID for new command matching in-flight command is illegal.""" 249 """Request ID for new command matching in-flight command is illegal."""
289 296
290 self.assertEqual(results[4][1], { 297 self.assertEqual(results[4][1], {
291 b'requestid': 3, 298 b'requestid': 3,
292 b'command': b'command3', 299 b'command': b'command3',
293 b'args': {b'biz': b'baz', b'key': b'val'}, 300 b'args': {b'biz': b'baz', b'key': b'val'},
301 b'redirect': None,
294 b'data': None, 302 b'data': None,
295 }) 303 })
296 self.assertEqual(results[5][1], { 304 self.assertEqual(results[5][1], {
297 b'requestid': 1, 305 b'requestid': 1,
298 b'command': b'command1', 306 b'command': b'command1',
299 b'args': {b'foo': b'bar', b'key1': b'val'}, 307 b'args': {b'foo': b'bar', b'key1': b'val'},
308 b'redirect': None,
300 b'data': None, 309 b'data': None,
301 }) 310 })
302 311
303 def testmissingcommanddataframe(self): 312 def testmissingcommanddataframe(self):
304 # The reactor doesn't currently handle partially received commands. 313 # The reactor doesn't currently handle partially received commands.