Patchwork [1,of,5] tests: explicitly flush output streams

login
register
mail settings
Submitter Jun Wu
Date March 15, 2016, 9:58 a.m.
Message ID <7d543ffcd496456bb8c1.1458035912@x1c>
Download mbox | patch
Permalink /patch/13892/
State Superseded
Commit 6fb1d3c936d2f80608963bdfcac1e75db2e69304
Delegated to: Yuya Nishihara
Headers show

Comments

Jun Wu - March 15, 2016, 9:58 a.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1458035502 0
#      Tue Mar 15 09:51:42 2016 +0000
# Node ID 7d543ffcd496456bb8c12b3755155250e969d688
# Parent  a51d7eb2e998920b2f4c4f7114cb8450df05ec44
tests: explicitly flush output streams

Some tests fail while running with chg because they do not flush their output
streams. chgserver will make sure ui.flush is called after dispatch, but not
after {ui,repo}setup. For other non-ui streams, it should be explicitly
flushed since the request handler will use os._exit.
This patch adds explicit flushes in test-bundle2-format.t, test-extension.t
and test-obsolete.t. It will fix most test cases of them when running with chg.
Yuya Nishihara - March 17, 2016, 1:59 p.m.
On Tue, 15 Mar 2016 09:58:32 +0000, Jun Wu wrote:
> # HG changeset patch
> # User Jun Wu <quark@fb.com>
> # Date 1458035502 0
> #      Tue Mar 15 09:51:42 2016 +0000
> # Node ID 7d543ffcd496456bb8c12b3755155250e969d688
> # Parent  a51d7eb2e998920b2f4c4f7114cb8450df05ec44
> tests: explicitly flush output streams
> 
> Some tests fail while running with chg because they do not flush their output
> streams. chgserver will make sure ui.flush is called after dispatch, but not
> after {ui,repo}setup. For other non-ui streams, it should be explicitly
> flushed since the request handler will use os._exit.
> This patch adds explicit flushes in test-bundle2-format.t, test-extension.t
> and test-obsolete.t. It will fix most test cases of them when running with chg.

> 
> diff --git a/tests/test-bundle2-format.t b/tests/test-bundle2-format.t
> --- a/tests/test-bundle2-format.t
> +++ b/tests/test-bundle2-format.t
> @@ -166,6 +166,8 @@
>    >             file.write(chunk)
>    >     except RuntimeError, exc:
>    >         raise error.Abort(exc)
> +  >     finally:
> +  >         file.flush()
>    > 
>    > @command('unbundle2', [], '')
>    > def cmdunbundle2(ui, repo, replypath=None):
> @@ -197,6 +199,7 @@
>    >         file = open(replypath, 'wb')
>    >         for chunk in op.reply.getchunks():
>    >             file.write(chunk)
> +  >         file.flush()

These two should be file.close(). cmdutil.makefileobj() might be useful.

> --- a/tests/test-extension.t
> +++ b/tests/test-extension.t
> @@ -7,9 +7,11 @@
>    > command = cmdutil.command(cmdtable)
>    > def uisetup(ui):
>    >     ui.write("uisetup called\\n")
> +  >     ui.flush()
>    > def reposetup(ui, repo):
>    >     ui.write("reposetup called for %s\\n" % os.path.basename(repo.root))
>    >     ui.write("ui %s= repo.ui\\n" % (ui == repo.ui and "=" or "!"))
> +  >     ui.flush()
>    > @command('foo', [], 'hg foo')
>    > def foo(ui, *args, **kwargs):
>    >     ui.write("Foo\\n")
> @@ -183,6 +185,7 @@
>    > import foo
>    > def extsetup(ui):
>    >     ui.write('(extroot) ', foo.func(), '\n')
> +  >     ui.flush()
>    > EOF
>  
>    $ cat > $TESTTMP/extroot/foo.py <<EOF
> @@ -1077,6 +1080,7 @@
>    > from mercurial import extensions
>    > def reposetup(ui, repo):
>    >     ui.write('reposetup() for %s\n' % (repo.root))
> +  >     ui.flush()

These looks good.

> diff --git a/tests/test-obsolete.t b/tests/test-obsolete.t
> --- a/tests/test-obsolete.t
> +++ b/tests/test-obsolete.t
> @@ -923,6 +923,7 @@
>  Test heads computation on pending index changes with obsolescence markers
>    $ cd ..
>    $ cat >$TESTTMP/test_extension.py  << EOF
> +  > import sys
>    > from mercurial import cmdutil
>    > from mercurial.i18n import _
>    > 
> @@ -936,6 +937,7 @@
>    >   opts['logfile'] = None
>    >   cmdutil.amend(ui, repo, commitfunc, repo['.'], {}, pats, opts)
>    >   print repo.changelog.headrevs()
> +  >   sys.stdout.flush()

Perhaps we should use ui.write() ?
Jun Wu - March 21, 2016, 1:04 a.m.
On 03/17/2016 06:59 AM, Yuya Nishihara wrote:
> These two should be file.close(). cmdutil.makefileobj() might be useful.

The first one can be sys.stdout so I will keep it just "flush".

Patch

diff --git a/tests/test-bundle2-format.t b/tests/test-bundle2-format.t
--- a/tests/test-bundle2-format.t
+++ b/tests/test-bundle2-format.t
@@ -166,6 +166,8 @@ 
   >             file.write(chunk)
   >     except RuntimeError, exc:
   >         raise error.Abort(exc)
+  >     finally:
+  >         file.flush()
   > 
   > @command('unbundle2', [], '')
   > def cmdunbundle2(ui, repo, replypath=None):
@@ -197,6 +199,7 @@ 
   >         file = open(replypath, 'wb')
   >         for chunk in op.reply.getchunks():
   >             file.write(chunk)
+  >         file.flush()
   > 
   > @command('statbundle2', [], '')
   > def cmdstatbundle2(ui, repo):
diff --git a/tests/test-extension.t b/tests/test-extension.t
--- a/tests/test-extension.t
+++ b/tests/test-extension.t
@@ -7,9 +7,11 @@ 
   > command = cmdutil.command(cmdtable)
   > def uisetup(ui):
   >     ui.write("uisetup called\\n")
+  >     ui.flush()
   > def reposetup(ui, repo):
   >     ui.write("reposetup called for %s\\n" % os.path.basename(repo.root))
   >     ui.write("ui %s= repo.ui\\n" % (ui == repo.ui and "=" or "!"))
+  >     ui.flush()
   > @command('foo', [], 'hg foo')
   > def foo(ui, *args, **kwargs):
   >     ui.write("Foo\\n")
@@ -183,6 +185,7 @@ 
   > import foo
   > def extsetup(ui):
   >     ui.write('(extroot) ', foo.func(), '\n')
+  >     ui.flush()
   > EOF
 
   $ cat > $TESTTMP/extroot/foo.py <<EOF
@@ -1077,6 +1080,7 @@ 
   > from mercurial import extensions
   > def reposetup(ui, repo):
   >     ui.write('reposetup() for %s\n' % (repo.root))
+  >     ui.flush()
   > EOF
   $ hg init src
   $ echo a > src/a
diff --git a/tests/test-obsolete.t b/tests/test-obsolete.t
--- a/tests/test-obsolete.t
+++ b/tests/test-obsolete.t
@@ -923,6 +923,7 @@ 
 Test heads computation on pending index changes with obsolescence markers
   $ cd ..
   $ cat >$TESTTMP/test_extension.py  << EOF
+  > import sys
   > from mercurial import cmdutil
   > from mercurial.i18n import _
   > 
@@ -936,6 +937,7 @@ 
   >   opts['logfile'] = None
   >   cmdutil.amend(ui, repo, commitfunc, repo['.'], {}, pats, opts)
   >   print repo.changelog.headrevs()
+  >   sys.stdout.flush()
   > EOF
   $ cat >> $HGRCPATH << EOF
   > [extensions]