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