Show More
@@ -1,118 +1,130 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(b'logtoprocess', b'foo', |
|
18 | 18 | > default=None, |
|
19 | 19 | > ) |
|
20 | 20 | > @command(b'foobar', []) |
|
21 | 21 | > def foo(ui, repo): |
|
22 | 22 | > ui.log(b'foo', b'a message: %s\n', b'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 | 30 | > command=(echo 'logtoprocess command output:'; |
|
31 | 31 | > echo "\$EVENT"; |
|
32 | 32 | > echo "\$MSG1") > $TESTTMP/command.log |
|
33 | 33 | > commandfinish=(echo 'logtoprocess commandfinish output:'; |
|
34 | 34 | > echo "\$EVENT"; |
|
35 | 35 | > echo "\$MSG1"; |
|
36 | 36 | > echo "canonical: \$OPT_CANONICAL_COMMAND") > $TESTTMP/commandfinish.log |
|
37 | 37 | > foo=(echo 'logtoprocess foo output:'; |
|
38 | 38 | > echo "\$EVENT"; |
|
39 | 39 | > echo "\$MSG1") > $TESTTMP/foo.log |
|
40 | 40 | > EOF |
|
41 | 41 | |
|
42 | 42 | Running a command triggers both a ui.log('command') and a |
|
43 | 43 | ui.log('commandfinish') call. The foo command also uses ui.log. |
|
44 | 44 | |
|
45 | 45 | Use sort to avoid ordering issues between the various processes we spawn: |
|
46 | 46 | $ hg fooba |
|
47 | 47 | $ sleep 1 |
|
48 | 48 | $ cat $TESTTMP/command.log | sort |
|
49 | 49 | |
|
50 | 50 | command |
|
51 | 51 | fooba |
|
52 | 52 | logtoprocess command output: |
|
53 | 53 | |
|
54 | 54 | #if no-chg |
|
55 | 55 | $ cat $TESTTMP/commandfinish.log | sort |
|
56 | 56 | |
|
57 | 57 | canonical: foobar |
|
58 | 58 | commandfinish |
|
59 | 59 | fooba exited 0 after * seconds (glob) |
|
60 | 60 | logtoprocess commandfinish output: |
|
61 | 61 | $ cat $TESTTMP/foo.log | sort |
|
62 | 62 | |
|
63 | 63 | a message: spam |
|
64 | 64 | foo |
|
65 | 65 | logtoprocess foo output: |
|
66 | 66 | #endif |
|
67 | 67 | |
|
68 | 68 | Confirm that logging blocked time catches stdio properly: |
|
69 | 69 | $ cp $HGRCPATH.bak $HGRCPATH |
|
70 | 70 | $ cat >> $HGRCPATH << EOF |
|
71 | 71 | > [extensions] |
|
72 | 72 | > logtoprocess= |
|
73 | 73 | > pager= |
|
74 | 74 | > [logtoprocess] |
|
75 | 75 | > uiblocked=echo "\$EVENT stdio \$OPT_STDIO_BLOCKED ms command \$OPT_COMMAND_DURATION ms" > $TESTTMP/uiblocked.log |
|
76 | 76 | > [ui] |
|
77 | 77 | > logblockedtimes=True |
|
78 | 78 | > EOF |
|
79 | 79 | |
|
80 | 80 | $ hg log |
|
81 | 81 | $ sleep 1 |
|
82 | 82 | $ cat $TESTTMP/uiblocked.log |
|
83 | 83 | uiblocked stdio [0-9]+.[0-9]* ms command [0-9]+.[0-9]* ms (re) |
|
84 | 84 | |
|
85 | 85 | Try to confirm that pager wait on logtoprocess: |
|
86 | 86 | |
|
87 | 87 | Add a script that wait on a file to appears for 5 seconds, if it sees it touch |
|
88 | 88 | another file or die after 5 seconds. If the scripts is awaited by hg, the |
|
89 | 89 | script will die after the timeout before we could touch the file and the |
|
90 | 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 | 102 | $ cat > $TESTTMP/wait-output.sh << EOF |
|
93 | 103 | > #!/bin/sh |
|
94 | 104 | > for i in \`$TESTDIR/seq.py 50\`; do |
|
95 | 105 | > if [ -f "$TESTTMP/wait-for-touched" ]; |
|
96 | 106 | > then |
|
97 | 107 | > touch "$TESTTMP/touched"; |
|
98 | 108 | > break; |
|
99 | 109 | > else |
|
100 | 110 | > sleep 0.1; |
|
101 | 111 | > fi |
|
102 | 112 | > done |
|
103 | 113 | > EOF |
|
104 | 114 | $ chmod +x $TESTTMP/wait-output.sh |
|
105 | 115 | |
|
106 | 116 | $ cat >> $HGRCPATH << EOF |
|
107 | 117 | > [extensions] |
|
108 | 118 | > logtoprocess= |
|
109 | 119 | > pager= |
|
120 | > [pager] | |
|
121 | > pager = "$PYTHON" $TESTTMP/fakepager.py | |
|
110 | 122 | > [logtoprocess] |
|
111 | 123 | > commandfinish=$TESTTMP/wait-output.sh |
|
112 | 124 | > EOF |
|
113 | 125 | $ hg version -q --pager=always |
|
114 | 126 | Mercurial Distributed SCM (version *) (glob) |
|
115 | 127 | $ touch $TESTTMP/wait-for-touched |
|
116 | 128 | $ sleep 0.2 |
|
117 | 129 | $ test -f $TESTTMP/touched && echo "SUCCESS Pager is not waiting on ltp" || echo "FAIL Pager is waiting on ltp" |
|
118 | 130 | SUCCESS Pager is not waiting on ltp |
General Comments 0
You need to be logged in to leave comments.
Login now