comparison tests/test-http-api-httpv2.t @ 39575:07b58266bce3

wireprotov2: implement commands as a generator of objects Previously, wire protocol version 2 inherited version 1's model of having separate types to represent the results of different wire protocol commands. As I implemented more powerful commands in future commits, I found I was using a common pattern of returning a special type to hold a generator. This meant the command function required a closure to do most of the work. That made logic flow more difficult to follow. I also noticed that many commands were effectively a sequence of objects to be CBOR encoded. I think it makes sense to define version 2 commands as generators. This way, commands can simply emit the data structures they wish to send to the client. This eliminates the need for a closure in command functions and removes encoding from the bodies of commands. As part of this commit, the handling of response objects has been moved into the serverreactor class. This puts the reactor in the driver's seat with regards to CBOR encoding and error handling. Having error handling in the function that emits frames is particularly important because exceptions in that function can lead to things getting in a bad state: I'm fairly certain that uncaught exceptions in the frame generator were causing deadlocks. I also introduced a dedicated error type for explicit error reporting in command handlers. This will be used in subsequent commits. There's still a bit of work to be done here, especially around formalizing the error handling "protocol." I've added yet another TODO to track this so we don't forget. Test output changed because we're using generators and no longer know we are at the end of the data until we hit the end of the generator. This means we can't emit the end-of-stream flag until we've exhausted the generator. Hence the introduction of 0-sized end-of-stream frames. Differential Revision: https://phab.mercurial-scm.org/D4472
author Gregory Szorc <gregory.szorc@gmail.com>
date Wed, 05 Sep 2018 09:06:40 -0700
parents 660879e49b46
children d06834e0f48e
comparison
equal deleted inserted replaced
39574:b0e0db1565d1 39575:07b58266bce3
174 s> Server: testing stub value\r\n 174 s> Server: testing stub value\r\n
175 s> Date: $HTTP_DATE$\r\n 175 s> Date: $HTTP_DATE$\r\n
176 s> Content-Type: application/mercurial-exp-framing-0005\r\n 176 s> Content-Type: application/mercurial-exp-framing-0005\r\n
177 s> Transfer-Encoding: chunked\r\n 177 s> Transfer-Encoding: chunked\r\n
178 s> \r\n 178 s> \r\n
179 s> 32\r\n 179 s> 13\r\n
180 s> *\x00\x00\x01\x00\x02\x012\xa1FstatusBokX\x1dcustomreadonly bytes response 180 s> \x0b\x00\x00\x01\x00\x02\x011\xa1FstatusBok
181 s> \r\n
182 s> 27\r\n
183 s> \x1f\x00\x00\x01\x00\x02\x001X\x1dcustomreadonly bytes response
184 s> \r\n
185 s> 8\r\n
186 s> \x00\x00\x00\x01\x00\x02\x002
181 s> \r\n 187 s> \r\n
182 s> 0\r\n 188 s> 0\r\n
183 s> \r\n 189 s> \r\n
184 190
185 $ sendhttpv2peer << EOF 191 $ sendhttpv2peer << EOF
201 s> Server: testing stub value\r\n 207 s> Server: testing stub value\r\n
202 s> Date: $HTTP_DATE$\r\n 208 s> Date: $HTTP_DATE$\r\n
203 s> Content-Type: application/mercurial-exp-framing-0005\r\n 209 s> Content-Type: application/mercurial-exp-framing-0005\r\n
204 s> Transfer-Encoding: chunked\r\n 210 s> Transfer-Encoding: chunked\r\n
205 s> \r\n 211 s> \r\n
206 s> 32\r\n 212 s> 13\r\n
207 s> *\x00\x00\x01\x00\x02\x012 213 s> \x0b\x00\x00\x01\x00\x02\x011
208 s> \xa1FstatusBokX\x1dcustomreadonly bytes response 214 s> \xa1FstatusBok
209 s> \r\n 215 s> \r\n
210 received frame(size=42; request=1; stream=2; streamflags=stream-begin; type=command-response; flags=eos) 216 received frame(size=11; request=1; stream=2; streamflags=stream-begin; type=command-response; flags=continuation)
217 s> 27\r\n
218 s> \x1f\x00\x00\x01\x00\x02\x001
219 s> X\x1dcustomreadonly bytes response
220 s> \r\n
221 received frame(size=31; request=1; stream=2; streamflags=; type=command-response; flags=continuation)
222 s> 8\r\n
223 s> \x00\x00\x00\x01\x00\x02\x002
224 s> \r\n
211 s> 0\r\n 225 s> 0\r\n
212 s> \r\n 226 s> \r\n
227 received frame(size=0; request=1; stream=2; streamflags=; type=command-response; flags=eos)
213 response: [ 228 response: [
214 { 229 {
215 b'status': b'ok' 230 b'status': b'ok'
216 }, 231 },
217 b'customreadonly bytes response' 232 b'customreadonly bytes response'
320 s> Server: testing stub value\r\n 335 s> Server: testing stub value\r\n
321 s> Date: $HTTP_DATE$\r\n 336 s> Date: $HTTP_DATE$\r\n
322 s> Content-Type: application/mercurial-exp-framing-0005\r\n 337 s> Content-Type: application/mercurial-exp-framing-0005\r\n
323 s> Transfer-Encoding: chunked\r\n 338 s> Transfer-Encoding: chunked\r\n
324 s> \r\n 339 s> \r\n
325 s> 32\r\n 340 s> 13\r\n
326 s> *\x00\x00\x01\x00\x02\x012\xa1FstatusBokX\x1dcustomreadonly bytes response 341 s> \x0b\x00\x00\x01\x00\x02\x011\xa1FstatusBok
342 s> \r\n
343 s> 27\r\n
344 s> \x1f\x00\x00\x01\x00\x02\x001X\x1dcustomreadonly bytes response
345 s> \r\n
346 s> 8\r\n
347 s> \x00\x00\x00\x01\x00\x02\x002
327 s> \r\n 348 s> \r\n
328 s> 0\r\n 349 s> 0\r\n
329 s> \r\n 350 s> \r\n
330 351
331 Authorized request for unknown command is rejected 352 Authorized request for unknown command is rejected
443 s> Server: testing stub value\r\n 464 s> Server: testing stub value\r\n
444 s> Date: $HTTP_DATE$\r\n 465 s> Date: $HTTP_DATE$\r\n
445 s> Content-Type: application/mercurial-exp-framing-0005\r\n 466 s> Content-Type: application/mercurial-exp-framing-0005\r\n
446 s> Transfer-Encoding: chunked\r\n 467 s> Transfer-Encoding: chunked\r\n
447 s> \r\n 468 s> \r\n
448 s> 32\r\n 469 s> 13\r\n
449 s> *\x00\x00\x01\x00\x02\x012\xa1FstatusBokX\x1dcustomreadonly bytes response 470 s> \x0b\x00\x00\x01\x00\x02\x011\xa1FstatusBok
471 s> \r\n
472 s> 27\r\n
473 s> \x1f\x00\x00\x01\x00\x02\x001X\x1dcustomreadonly bytes response
474 s> \r\n
475 s> 8\r\n
476 s> \x00\x00\x00\x01\x00\x02\x002
450 s> \r\n 477 s> \r\n
451 s> 0\r\n 478 s> 0\r\n
452 s> \r\n 479 s> \r\n
453 480
454 Multiple requests to "multirequest" URL are allowed 481 Multiple requests to "multirequest" URL are allowed
476 s> Server: testing stub value\r\n 503 s> Server: testing stub value\r\n
477 s> Date: $HTTP_DATE$\r\n 504 s> Date: $HTTP_DATE$\r\n
478 s> Content-Type: application/mercurial-exp-framing-0005\r\n 505 s> Content-Type: application/mercurial-exp-framing-0005\r\n
479 s> Transfer-Encoding: chunked\r\n 506 s> Transfer-Encoding: chunked\r\n
480 s> \r\n 507 s> \r\n
481 s> 32\r\n 508 s> 13\r\n
482 s> *\x00\x00\x01\x00\x02\x012\xa1FstatusBokX\x1dcustomreadonly bytes response 509 s> \x0b\x00\x00\x01\x00\x02\x011\xa1FstatusBok
483 s> \r\n 510 s> \r\n
484 s> 32\r\n 511 s> 27\r\n
485 s> *\x00\x00\x03\x00\x02\x002\xa1FstatusBokX\x1dcustomreadonly bytes response 512 s> \x1f\x00\x00\x01\x00\x02\x001X\x1dcustomreadonly bytes response
513 s> \r\n
514 s> 8\r\n
515 s> \x00\x00\x00\x01\x00\x02\x002
516 s> \r\n
517 s> 13\r\n
518 s> \x0b\x00\x00\x03\x00\x02\x001\xa1FstatusBok
519 s> \r\n
520 s> 27\r\n
521 s> \x1f\x00\x00\x03\x00\x02\x001X\x1dcustomreadonly bytes response
522 s> \r\n
523 s> 8\r\n
524 s> \x00\x00\x00\x03\x00\x02\x002
486 s> \r\n 525 s> \r\n
487 s> 0\r\n 526 s> 0\r\n
488 s> \r\n 527 s> \r\n
489 528
490 Interleaved requests to "multirequest" are processed 529 Interleaved requests to "multirequest" are processed
514 s> Server: testing stub value\r\n 553 s> Server: testing stub value\r\n
515 s> Date: $HTTP_DATE$\r\n 554 s> Date: $HTTP_DATE$\r\n
516 s> Content-Type: application/mercurial-exp-framing-0005\r\n 555 s> Content-Type: application/mercurial-exp-framing-0005\r\n
517 s> Transfer-Encoding: chunked\r\n 556 s> Transfer-Encoding: chunked\r\n
518 s> \r\n 557 s> \r\n
519 s> 33\r\n 558 s> 13\r\n
520 s> +\x00\x00\x03\x00\x02\x012\xa1FstatusBok\xa3Ibookmarks@Jnamespaces@Fphases@ 559 s> \x0b\x00\x00\x03\x00\x02\x011\xa1FstatusBok
521 s> \r\n 560 s> \r\n
522 s> 14\r\n 561 s> 28\r\n
523 s> \x0c\x00\x00\x01\x00\x02\x002\xa1FstatusBok\xa0 562 s> \x00\x00\x03\x00\x02\x001\xa3Ibookmarks@Jnamespaces@Fphases@
563 s> \r\n
564 s> 8\r\n
565 s> \x00\x00\x00\x03\x00\x02\x002
566 s> \r\n
567 s> 13\r\n
568 s> \x0b\x00\x00\x01\x00\x02\x001\xa1FstatusBok
569 s> \r\n
570 s> 9\r\n
571 s> \x01\x00\x00\x01\x00\x02\x001\xa0
572 s> \r\n
573 s> 8\r\n
574 s> \x00\x00\x00\x01\x00\x02\x002
524 s> \r\n 575 s> \r\n
525 s> 0\r\n 576 s> 0\r\n
526 s> \r\n 577 s> \r\n
527 578
528 Restart server to disable read-write access 579 Restart server to disable read-write access