# HG changeset patch # User Gregory Szorc # Date 2018-03-12 22:49:02 # Node ID 143219fc2620ce59423200f7b4c830c42c2c3279 # Parent 8e89c2bec1f767b4866168d9a71b74c365cdb202 debugcommands: introduce actions to perform deterministic reads "readavailable" is useful as a debugging device to see what data is available on a pipe. But the mechanism isn't deterministic because what's available on a pipe is highly conditional on timing, system load, OS behavior, etc. This makes it not suitable for tests. We introduce "ereadline," "read," and "eread" for performing deterministic I/O operations (at least on blocking file descriptors). We stop short of converting existing consumers of "readavailable" in tests because we're working out race conditions and deadlocks on Windows. But the goal is to eventually move tests away from "readavailable" to these new APIs. Differential Revision: https://phab.mercurial-scm.org/D2720 diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py --- a/mercurial/debugcommands.py +++ b/mercurial/debugcommands.py @@ -2715,6 +2715,21 @@ def debugwireproto(ui, repo, **opts): Read a line of output from the server. If there are multiple output pipes, reads only the main pipe. + + ereadline + --------- + + Like ``readline``, but read from the stderr pipe, if available. + + read + -------- + + ``read()`` N bytes from the server's main output pipe. + + eread + --------- + + ``read()`` N bytes from the server's stderr pipe, if available. """ opts = pycompat.byteskwargs(opts) @@ -2855,6 +2870,14 @@ def debugwireproto(ui, repo, **opts): stderr.read() elif action == 'readline': stdout.readline() + elif action == 'ereadline': + stderr.readline() + elif action.startswith('read '): + count = int(action.split(' ', 1)[1]) + stdout.read(count) + elif action.startswith('eread '): + count = int(action.split(' ', 1)[1]) + stderr.read(count) else: raise error.Abort(_('unknown action: %s') % action)