This is an archive of the discontinued Mercurial Phabricator instance.

wireproto: implement basic frame reading and processing
ClosedPublic

Authored by indygreg on Mar 13 2018, 10:49 PM.

Details

Summary

We just implemented support for writing frames. Now let's implement
support for reading them.

The bulk of the new code is for a class that maintains the state of
a server. Essentially, you construct an instance, feed frames to it,
and it tells you what you should do next. The design is inspired by
the "sans I/O" movement and the reactor pattern. We don't want to
perform I/O or any major blocking event during frame ingestion because
this arbitrarily limits ways that server pieces can be implemented.
For example, it makes it much harder to swap in an alternate
implementation based on asyncio or do crazy things like have requests
dispatch to other processes.

We do still implement readframe() which does I/O. But it is decoupled
from the server reactor. And important parsing of frame headers is
a standalone function. So I/O is only needed to obtain frame data.

Because testing server-side ingest is useful and difficult on running
servers, we create a new "debugreflect" endpoint that will echo back
to the client what was received and how it was interpreted. This could
be useful for a server admin, someone implementing a client. But
immediately, it is useful for testing: we're able to demonstrate that
frames are parsed correctly and turned into requests to run commands
without having to implement command dispatch on the server!

In addition, we implement Python level unit tests for the reactor.
This is vastly more efficient than sending requests to the
"debugreflect" endpoint and vastly more powerful for advanced
testing.

Diff Detail

Repository
rHG Mercurial
Lint
Lint Skipped
Unit
Unit Tests Skipped

Event Timeline

indygreg created this revision.Mar 13 2018, 10:49 PM
indygreg abandoned this revision.Mar 14 2018, 3:21 PM
indygreg added inline comments.
mercurial/wireprotoframing.py
82–88

I have a minor refactor of this code locally so we can better support "sans I/O." Will send a new version once someone starts to look at this series.

indygreg edited the summary of this revision. (Show Details)Mar 14 2018, 9:10 PM
indygreg updated this revision to Diff 7048.
indygreg updated this revision to Diff 7140.Mar 19 2018, 7:59 PM
durin42 accepted this revision.Mar 21 2018, 9:32 PM
This revision is now accepted and ready to land.Mar 21 2018, 9:32 PM
This revision was automatically updated to reflect the committed changes.
yuja added a subscriber: yuja.Mar 24 2018, 10:48 AM
yuja added inline comments.
mercurial/util.py
2566

I think read() never returns None.

mercurial/wireprotoserver.py
402

This wouldn't work on Python 3 because JSON requires unicode.