##// END OF EJS Templates
logtoprocess: add a test to show pager and ltp bad interaction...
Boris Feld -
r39961:dfca8359 default
parent child Browse files
Show More
@@ -1,85 +1,124 b''
1 1 #require no-windows
2 2
3 3 ATTENTION: logtoprocess runs commands asynchronously. Be sure to append "| cat"
4 4 to hg commands, to wait for the output, if you want to test its output.
5 5 Otherwise the test will be flaky.
6 6
7 7 Test if logtoprocess correctly captures command-related log calls.
8 8
9 9 $ hg init
10 10 $ cat > $TESTTMP/foocommand.py << EOF
11 11 > from __future__ import absolute_import
12 12 > from mercurial import registrar
13 13 > cmdtable = {}
14 14 > command = registrar.command(cmdtable)
15 15 > configtable = {}
16 16 > configitem = registrar.configitem(configtable)
17 17 > configitem('logtoprocess', 'foo',
18 18 > default=None,
19 19 > )
20 20 > @command(b'foo', [])
21 21 > def foo(ui, repo):
22 22 > ui.log('foo', 'a message: %(bar)s\n', bar='spam')
23 23 > EOF
24 24 $ cp $HGRCPATH $HGRCPATH.bak
25 25 $ cat >> $HGRCPATH << EOF
26 26 > [extensions]
27 27 > logtoprocess=
28 28 > foocommand=$TESTTMP/foocommand.py
29 29 > [logtoprocess]
30 > command=echo 'logtoprocess command output:';
30 > command=(echo 'logtoprocess command output:';
31 31 > echo "\$EVENT";
32 32 > echo "\$MSG1";
33 > echo "\$MSG2"
34 > commandfinish=echo 'logtoprocess commandfinish output:';
33 > echo "\$MSG2") > $TESTTMP/command.log
34 > commandfinish=(echo 'logtoprocess commandfinish output:';
35 35 > echo "\$EVENT";
36 36 > echo "\$MSG1";
37 37 > echo "\$MSG2";
38 > echo "\$MSG3"
39 > foo=echo 'logtoprocess foo output:';
38 > echo "\$MSG3") > $TESTTMP/commandfinish.log
39 > foo=(echo 'logtoprocess foo output:';
40 40 > echo "\$EVENT";
41 41 > echo "\$MSG1";
42 > echo "\$OPT_BAR"
42 > echo "\$OPT_BAR") > $TESTTMP/foo.log
43 43 > EOF
44 44
45 45 Running a command triggers both a ui.log('command') and a
46 46 ui.log('commandfinish') call. The foo command also uses ui.log.
47 47
48 48 Use sort to avoid ordering issues between the various processes we spawn:
49 $ hg foo | cat | sort
50
51
49 $ hg foo
50 $ sleep 0.2
51 $ cat $TESTTMP/command.log | sort
52 52
53 (chg !)
53 command
54 foo
55 foo
56 logtoprocess command output:
57
58 #if no-chg
59 $ cat $TESTTMP/commandfinish.log | sort
60
54 61 0
55 a message: spam
56 command
57 command (chg !)
58 62 commandfinish
59 63 foo
60 foo
61 foo
64 foo exited 0 after * seconds (glob)
65 logtoprocess commandfinish output:
66 $ cat $TESTTMP/foo.log | sort
67
68 a message: spam
62 69 foo
63 foo exited 0 after * seconds (glob)
64 logtoprocess command output:
65 logtoprocess command output: (chg !)
66 logtoprocess commandfinish output:
67 70 logtoprocess foo output:
68 serve --cmdserver chgunix * (glob) (chg !)
69 serve --cmdserver chgunix * (glob) (chg !)
70 71 spam
72 #endif
71 73
72 74 Confirm that logging blocked time catches stdio properly:
73 75 $ cp $HGRCPATH.bak $HGRCPATH
74 76 $ cat >> $HGRCPATH << EOF
75 77 > [extensions]
76 78 > logtoprocess=
77 79 > pager=
78 80 > [logtoprocess]
79 > uiblocked=echo "\$EVENT stdio \$OPT_STDIO_BLOCKED ms command \$OPT_COMMAND_DURATION ms"
81 > uiblocked=echo "\$EVENT stdio \$OPT_STDIO_BLOCKED ms command \$OPT_COMMAND_DURATION ms" > $TESTTMP/uiblocked.log
80 82 > [ui]
81 83 > logblockedtimes=True
82 84 > EOF
83 85
84 $ hg log | cat
86 $ hg log
87 $ sleep 0.2
88 $ cat $TESTTMP/uiblocked.log
85 89 uiblocked stdio [0-9]+.[0-9]* ms command [0-9]+.[0-9]* ms (re)
90
91 Try to confirm that pager wait on logtoprocess:
92
93 Add a script that wait on a file to appears for 5 seconds, if it sees it touch
94 another file or die after 5 seconds. If the scripts is awaited by hg, the
95 script will die after the timeout before we could touch the file and the
96 resulting file will not exists. If not, we will touch the file and see it.
97
98 $ cat > $TESTTMP/wait-output.sh << EOF
99 > #!/bin/sh
100 > for i in \`$TESTDIR/seq.py 50\`; do
101 > if [ -f "$TESTTMP/wait-for-touched" ];
102 > then
103 > touch "$TESTTMP/touched";
104 > break;
105 > else
106 > sleep 0.1;
107 > fi
108 > done
109 > EOF
110 $ chmod +x $TESTTMP/wait-output.sh
111
112 $ cat >> $HGRCPATH << EOF
113 > [extensions]
114 > logtoprocess=
115 > pager=
116 > [logtoprocess]
117 > commandfinish=$TESTTMP/wait-output.sh
118 > EOF
119 $ hg version -q --pager=always
120 Mercurial Distributed SCM (version *) (glob)
121 $ touch $TESTTMP/wait-for-touched
122 $ sleep 0.2
123 $ test -f $TESTTMP/touched && echo "SUCCESS Pager is not waiting on ltp" || echo "FAIL Pager is waiting on ltp"
124 FAIL Pager is waiting on ltp
General Comments 0
You need to be logged in to leave comments. Login now