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