[PATCH 1 of 3] test-ssh: add some flush() to make output deterministic

Yuya Nishihara yuya at tcha.org
Fri May 11 21:42:18 EDT 2018

On Fri, 11 May 2018 14:08:18 -0700, Gregory Szorc wrote:
> On Mon, May 7, 2018 at 6:11 AM, Yuya Nishihara <yuya at tcha.org> wrote:
> > # HG changeset patch
> > # User Yuya Nishihara <yuya at tcha.org>
> > # Date 1521963557 -32400
> > #      Sun Mar 25 16:39:17 2018 +0900
> > # Node ID 2be95f3cc4f8a4b59f7c50af093ea033d1d09c5e
> > # Parent  04ceb267271a45ae08352d76a9e91f8037ce53e7
> > test-ssh: add some flush() to make output deterministic
> >
> > We shouldn't rely on buffering mode/state of file handles.
> >
> I'm accepting this and understand why we need a flush() to make behavior
> deterministic.

Basically I inserted flush() where crossing underlying file objects, e.g.
between print() and ui.write(). Some of the last ui.flush() might be
unnecessary. OTOH, writing to sys.std* in in-process hooks is API violation,
so we wouldn't have to care seriously about that.

> However, I think we should consider adding the flush() to the code that
> invokes the hooks - not the hooks themselves. In theory, hook output is
> streamed to clients. So if we want to ensure hook output is seen by clients
> soon after it is generated, I think we should be flushing output
> automatically when invoking hooks. In the context of wire protocol
> requests, perhaps we should always be making the ui object unbuffered?

Maybe we can simply do ui.flush() at the end of runhooks()? It wouldn't be
easy to change the buffering mode of open files.

More information about the Mercurial-devel mailing list