##// END OF EJS Templates
wireprotov2: implement commands as a generator of objects...
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

File last commit:

r36757:f4a508f4 default
r39595:07b58266 default
Show More
blackbox-readonly-dispatch.py
38 lines | 1.1 KiB | text/x-python | PythonLexer
/ tests / blackbox-readonly-dispatch.py
Yuya Nishihara
py3: make blackbox-readonly-dispatch.py use ui instead of print()
r36756 from __future__ import absolute_import
timeless
tests: divorce blackbox test from test-dispatch.py...
r28406 import os
from mercurial import (
dispatch,
Yuya Nishihara
py3: make blackbox-readonly-dispatch.py use ui instead of print()
r36756 ui as uimod,
timeless
tests: divorce blackbox test from test-dispatch.py...
r28406 )
def testdispatch(cmd):
"""Simple wrapper around dispatch.dispatch()
Prints command and result value, but does not handle quoting.
"""
Yuya Nishihara
py3: make blackbox-readonly-dispatch.py use ui instead of print()
r36756 ui = uimod.ui.load()
Yuya Nishihara
py3: byte-stringify blackbox-readonly-dispatch.py...
r36757 ui.status(b"running: %s\n" % cmd)
Yuya Nishihara
py3: make blackbox-readonly-dispatch.py use ui instead of print()
r36756 req = dispatch.request(cmd.split(), ui)
timeless
tests: divorce blackbox test from test-dispatch.py...
r28406 result = dispatch.dispatch(req)
Yuya Nishihara
py3: byte-stringify blackbox-readonly-dispatch.py...
r36757 ui.status(b"result: %r\n" % result)
timeless
tests: divorce blackbox test from test-dispatch.py...
r28406
# create file 'foo', add and commit
Yuya Nishihara
py3: byte-stringify blackbox-readonly-dispatch.py...
r36757 f = open(b'foo', 'wb')
f.write(b'foo\n')
timeless
tests: divorce blackbox test from test-dispatch.py...
r28406 f.close()
Yuya Nishihara
py3: byte-stringify blackbox-readonly-dispatch.py...
r36757 testdispatch(b"--debug add foo")
testdispatch(b"--debug commit -m commit1 -d 2000-01-01 foo")
timeless
tests: divorce blackbox test from test-dispatch.py...
r28406
# append to file 'foo' and commit
Yuya Nishihara
py3: byte-stringify blackbox-readonly-dispatch.py...
r36757 f = open(b'foo', 'ab')
f.write(b'bar\n')
timeless
tests: divorce blackbox test from test-dispatch.py...
r28406 f.close()
# remove blackbox.log directory (proxy for readonly log file)
Yuya Nishihara
py3: byte-stringify blackbox-readonly-dispatch.py...
r36757 os.rmdir(b".hg/blackbox.log")
timeless
tests: divorce blackbox test from test-dispatch.py...
r28406 # replace it with the real blackbox.log file
Yuya Nishihara
py3: byte-stringify blackbox-readonly-dispatch.py...
r36757 os.rename(b".hg/blackbox.log-", b".hg/blackbox.log")
testdispatch(b"--debug commit -m commit2 -d 2000-01-02 foo")
timeless
tests: divorce blackbox test from test-dispatch.py...
r28406
# check 88803a69b24 (fancyopts modified command table)
Yuya Nishihara
py3: byte-stringify blackbox-readonly-dispatch.py...
r36757 testdispatch(b"--debug log -r 0")
testdispatch(b"--debug log -r tip")