Patchwork [2,of,2] test-chg: add basic tests for server lifecycle

login
register
mail settings
Submitter Yuya Nishihara
Date May 29, 2016, 1:40 p.m.
Message ID <ad80b1f43bf9a6648df5.1464529253@mimosa>
Download mbox | patch
Permalink /patch/15239/
State Accepted
Headers show

Comments

Yuya Nishihara - May 29, 2016, 1:40 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1463834609 -32400
#      Sat May 21 21:43:29 2016 +0900
# Node ID ad80b1f43bf9a6648df57959d47307e67cb88168
# Parent  f4d797228ecddcebfe86a9f726cdd55df49ef874
test-chg: add basic tests for server lifecycle

I'm going to move around the codes in AutoExitMixIn. This test should catch
a subtle bug of unlinking sockets which I made in draft patches.
Augie Fackler - May 29, 2016, 9:25 p.m.
On Sun, May 29, 2016 at 10:40:53PM +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1463834609 -32400
> #      Sat May 21 21:43:29 2016 +0900
> # Node ID ad80b1f43bf9a6648df57959d47307e67cb88168
> # Parent  f4d797228ecddcebfe86a9f726cdd55df49ef874
> test-chg: add basic tests for server lifecycle

Queued these, thanks!

>
> I'm going to move around the codes in AutoExitMixIn. This test should catch
> a subtle bug of unlinking sockets which I made in draft patches.
>
> diff --git a/tests/test-chg.t b/tests/test-chg.t
> --- a/tests/test-chg.t
> +++ b/tests/test-chg.t
> @@ -1,5 +1,7 @@
>  #require chg
>
> +  $ cp $HGRCPATH $HGRCPATH.orig
> +
>  init repo
>
>    $ chg init foo
> @@ -32,3 +34,73 @@ alias having an environment variable and
>    P1
>    $ A=2 chg printa
>    P2
> +
> +  $ cp $HGRCPATH.orig $HGRCPATH
> +  $ cd ..
> +
> +server lifecycle
> +----------------
> +
> +chg server should be restarted on code change, and old server will shut down
> +automatically. In this test, we use the following time parameters:
> +
> + - "sleep 1" to make mtime different
> + - "sleep 2" to notice mtime change (polling interval is 1 sec)
> +
> +set up repository with an extension:
> +
> +  $ chg init extreload
> +  $ cd extreload
> +  $ touch dummyext.py
> +  $ cat <<EOF >> .hg/hgrc
> +  > [extensions]
> +  > dummyext = dummyext.py
> +  > EOF
> +
> +isolate socket directory for stable result:
> +
> +  $ OLDCHGSOCKNAME=$CHGSOCKNAME
> +  $ mkdir chgsock
> +  $ CHGSOCKNAME=`pwd`/chgsock/server
> +
> +warm up server:
> +
> +  $ CHGDEBUG= chg log 2>&1 | egrep 'instruction|start'
> +  chg: debug: start cmdserver at $TESTTMP/extreload/chgsock/server
> +
> +new server should be started if extension modified:
> +
> +  $ sleep 1
> +  $ touch dummyext.py
> +  $ CHGDEBUG= chg log 2>&1 | egrep 'instruction|start'
> +  chg: debug: instruction: unlink $TESTTMP/extreload/chgsock/server-* (glob)
> +  chg: debug: instruction: reconnect
> +  chg: debug: start cmdserver at $TESTTMP/extreload/chgsock/server
> +
> +old server will shut down, while new server should still be reachable:
> +
> +  $ sleep 2
> +  $ CHGDEBUG= chg log 2>&1 | (egrep 'instruction|start' || true)
> +
> +socket file should never be unlinked by old server:
> +(simulates unowned socket by updating mtime, which makes sure server exits
> +at polling cycle)
> +
> +  $ ls chgsock/server-*
> +  chgsock/server-* (glob)
> +  $ touch chgsock/server-*
> +  $ sleep 2
> +  $ ls chgsock/server-*
> +  chgsock/server-* (glob)
> +
> +since no server is reachable from socket file, new server should be started:
> +(this test makes sure that old server shut down automatically)
> +
> +  $ CHGDEBUG= chg log 2>&1 | egrep 'instruction|start'
> +  chg: debug: start cmdserver at $TESTTMP/extreload/chgsock/server
> +
> +shut down servers and restore environment:
> +
> +  $ rm -R chgsock
> +  $ CHGSOCKNAME=$OLDCHGSOCKNAME
> +  $ cd ..
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

diff --git a/tests/test-chg.t b/tests/test-chg.t
--- a/tests/test-chg.t
+++ b/tests/test-chg.t
@@ -1,5 +1,7 @@ 
 #require chg
 
+  $ cp $HGRCPATH $HGRCPATH.orig
+
 init repo
 
   $ chg init foo
@@ -32,3 +34,73 @@  alias having an environment variable and
   P1
   $ A=2 chg printa
   P2
+
+  $ cp $HGRCPATH.orig $HGRCPATH
+  $ cd ..
+
+server lifecycle
+----------------
+
+chg server should be restarted on code change, and old server will shut down
+automatically. In this test, we use the following time parameters:
+
+ - "sleep 1" to make mtime different
+ - "sleep 2" to notice mtime change (polling interval is 1 sec)
+
+set up repository with an extension:
+
+  $ chg init extreload
+  $ cd extreload
+  $ touch dummyext.py
+  $ cat <<EOF >> .hg/hgrc
+  > [extensions]
+  > dummyext = dummyext.py
+  > EOF
+
+isolate socket directory for stable result:
+
+  $ OLDCHGSOCKNAME=$CHGSOCKNAME
+  $ mkdir chgsock
+  $ CHGSOCKNAME=`pwd`/chgsock/server
+
+warm up server:
+
+  $ CHGDEBUG= chg log 2>&1 | egrep 'instruction|start'
+  chg: debug: start cmdserver at $TESTTMP/extreload/chgsock/server
+
+new server should be started if extension modified:
+
+  $ sleep 1
+  $ touch dummyext.py
+  $ CHGDEBUG= chg log 2>&1 | egrep 'instruction|start'
+  chg: debug: instruction: unlink $TESTTMP/extreload/chgsock/server-* (glob)
+  chg: debug: instruction: reconnect
+  chg: debug: start cmdserver at $TESTTMP/extreload/chgsock/server
+
+old server will shut down, while new server should still be reachable:
+
+  $ sleep 2
+  $ CHGDEBUG= chg log 2>&1 | (egrep 'instruction|start' || true)
+
+socket file should never be unlinked by old server:
+(simulates unowned socket by updating mtime, which makes sure server exits
+at polling cycle)
+
+  $ ls chgsock/server-*
+  chgsock/server-* (glob)
+  $ touch chgsock/server-*
+  $ sleep 2
+  $ ls chgsock/server-*
+  chgsock/server-* (glob)
+
+since no server is reachable from socket file, new server should be started:
+(this test makes sure that old server shut down automatically)
+
+  $ CHGDEBUG= chg log 2>&1 | egrep 'instruction|start'
+  chg: debug: start cmdserver at $TESTTMP/extreload/chgsock/server
+
+shut down servers and restore environment:
+
+  $ rm -R chgsock
+  $ CHGSOCKNAME=$OLDCHGSOCKNAME
+  $ cd ..