comparison mercurial/debugcommands.py @ 37007:143219fc2620

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
author Gregory Szorc <gregory.szorc@gmail.com>
date Mon, 12 Mar 2018 15:49:02 -0700
parents 317382151ac3
children fc8939825632
comparison
equal deleted inserted replaced
37006:8e89c2bec1f7 37007:143219fc2620
2713 readline 2713 readline
2714 -------- 2714 --------
2715 2715
2716 Read a line of output from the server. If there are multiple output 2716 Read a line of output from the server. If there are multiple output
2717 pipes, reads only the main pipe. 2717 pipes, reads only the main pipe.
2718
2719 ereadline
2720 ---------
2721
2722 Like ``readline``, but read from the stderr pipe, if available.
2723
2724 read <X>
2725 --------
2726
2727 ``read()`` N bytes from the server's main output pipe.
2728
2729 eread <X>
2730 ---------
2731
2732 ``read()`` N bytes from the server's stderr pipe, if available.
2718 """ 2733 """
2719 opts = pycompat.byteskwargs(opts) 2734 opts = pycompat.byteskwargs(opts)
2720 2735
2721 if opts['localssh'] and not repo: 2736 if opts['localssh'] and not repo:
2722 raise error.Abort(_('--localssh requires a repository')) 2737 raise error.Abort(_('--localssh requires a repository'))
2853 stdin.close() 2868 stdin.close()
2854 stdout.read() 2869 stdout.read()
2855 stderr.read() 2870 stderr.read()
2856 elif action == 'readline': 2871 elif action == 'readline':
2857 stdout.readline() 2872 stdout.readline()
2873 elif action == 'ereadline':
2874 stderr.readline()
2875 elif action.startswith('read '):
2876 count = int(action.split(' ', 1)[1])
2877 stdout.read(count)
2878 elif action.startswith('eread '):
2879 count = int(action.split(' ', 1)[1])
2880 stderr.read(count)
2858 else: 2881 else:
2859 raise error.Abort(_('unknown action: %s') % action) 2882 raise error.Abort(_('unknown action: %s') % action)
2860 2883
2861 if batchedcommands is not None: 2884 if batchedcommands is not None:
2862 raise error.Abort(_('unclosed "batchbegin" request')) 2885 raise error.Abort(_('unclosed "batchbegin" request'))