##// 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:

r38081:fc3cca40 default
r39595:07b58266 default
Show More
test-bugzilla.t
104 lines | 2.9 KiB | text/troff | Tads3Lexer
Yuya Nishihara
bugzilla: do not load style file if template is specified (BC)...
r28950 mock bugzilla driver for testing template output:
$ cat <<EOF > bzmock.py
> from __future__ import absolute_import
> from mercurial import extensions
Boris Feld
configitems: register the 'bugzilla.mocklog' config
r33432 > from mercurial import registrar
Yuya Nishihara
bugzilla: do not load style file if template is specified (BC)...
r28950 >
Boris Feld
configitems: register the 'bugzilla.mocklog' config
r33432 > configtable = {}
> configitem = registrar.configitem(configtable)
>
Pulkit Goyal
py3: add b'' prefixes in tests/test-bugzilla.t...
r38081 > configitem(b'bugzilla', b'mocklog',
Boris Feld
configitems: register the 'bugzilla.mocklog' config
r33432 > default=None,
> )
Yuya Nishihara
bugzilla: do not load style file if template is specified (BC)...
r28950 > def extsetup(ui):
Pulkit Goyal
py3: add b'' prefixes in tests/test-bugzilla.t...
r38081 > bugzilla = extensions.find(b'bugzilla')
Yuya Nishihara
bugzilla: do not load style file if template is specified (BC)...
r28950 > class bzmock(bugzilla.bzaccess):
> def __init__(self, ui):
> super(bzmock, self).__init__(ui)
Pulkit Goyal
py3: add b'' prefixes in tests/test-bugzilla.t...
r38081 > self._logfile = ui.config(b'bugzilla', b'mocklog')
Yuya Nishihara
bugzilla: do not load style file if template is specified (BC)...
r28950 > def updatebug(self, bugid, newstate, text, committer):
> with open(self._logfile, 'a') as f:
> f.write('update bugid=%r, newstate=%r, committer=%r\n'
> % (bugid, newstate, committer))
> f.write('----\n' + text + '\n----\n')
> def notify(self, bugs, committer):
> with open(self._logfile, 'a') as f:
> f.write('notify bugs=%r, committer=%r\n'
> % (bugs, committer))
Pulkit Goyal
py3: add b'' prefixes in tests/test-bugzilla.t...
r38081 > bugzilla.bugzilla._versions[b'mock'] = bzmock
Yuya Nishihara
bugzilla: do not load style file if template is specified (BC)...
r28950 > EOF
set up mock repository:
$ hg init mockremote
$ cat <<EOF > mockremote/.hg/hgrc
> [extensions]
> bugzilla =
> bzmock = $TESTTMP/bzmock.py
>
> [bugzilla]
> version = mock
> mocklog = $TESTTMP/bzmock.log
>
> [hooks]
> incoming.bugzilla = python:hgext.bugzilla.hook
>
> [web]
> baseurl=http://example.org/hg
>
> %include $TESTTMP/bzstyle.hgrc
> EOF
$ hg clone -q mockremote mocklocal
push with default template:
$ echo '[bugzilla]' > bzstyle.hgrc
$ echo foo > mocklocal/foo
$ hg ci -R mocklocal -Aqm 'Fixes bug 123'
$ hg -R mocklocal push -q
$ cat bzmock.log && rm bzmock.log
update bugid=123, newstate={}, committer='test'
----
Matt Harbison
tests: remove (glob) annotations that were only for '\' matches...
r35394 changeset 7875a8342c6f in repo $TESTTMP/mockremote refers to bug 123.
Yuya Nishihara
bugzilla: do not load style file if template is specified (BC)...
r28950 details:
Fixes bug 123
----
notify bugs={123: {}}, committer='test'
push with style:
$ cat <<EOF > bzstyle.map
> changeset = "{node|short} refers to bug {bug}."
> EOF
$ echo "style = $TESTTMP/bzstyle.map" >> bzstyle.hgrc
$ echo foo >> mocklocal/foo
$ hg ci -R mocklocal -qm 'Fixes bug 456'
$ hg -R mocklocal push -q
$ cat bzmock.log && rm bzmock.log
update bugid=456, newstate={}, committer='test'
----
2808b172464b refers to bug 456.
----
notify bugs={456: {}}, committer='test'
push with template (overrides style):
$ cat <<EOF >> bzstyle.hgrc
> template = Changeset {node|short} in {root|basename}.
> {hgweb}/rev/{node|short}\n
> {desc}
> EOF
$ echo foo >> mocklocal/foo
$ hg ci -R mocklocal -qm 'Fixes bug 789'
$ hg -R mocklocal push -q
$ cat bzmock.log && rm bzmock.log
update bugid=789, newstate={}, committer='test'
----
Changeset a770f3e409f2 in mockremote.
http://example.org/hg/rev/a770f3e409f2
Fixes bug 789
----
notify bugs={789: {}}, committer='test'