##// END OF EJS Templates
tests: sleep longer in test-logtoprocess.t...
Augie Fackler -
r40413:18da306e default
parent child Browse files
Show More
@@ -1,124 +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 30 > command=(echo 'logtoprocess command output:';
31 31 > echo "\$EVENT";
32 32 > echo "\$MSG1";
33 33 > echo "\$MSG2") > $TESTTMP/command.log
34 34 > commandfinish=(echo 'logtoprocess commandfinish output:';
35 35 > echo "\$EVENT";
36 36 > echo "\$MSG1";
37 37 > echo "\$MSG2";
38 38 > echo "\$MSG3") > $TESTTMP/commandfinish.log
39 39 > foo=(echo 'logtoprocess foo output:';
40 40 > echo "\$EVENT";
41 41 > echo "\$MSG1";
42 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 49 $ hg foo
50 $ sleep 0.2
50 $ sleep 1
51 51 $ cat $TESTTMP/command.log | sort
52 52
53 53 command
54 54 foo
55 55 foo
56 56 logtoprocess command output:
57 57
58 58 #if no-chg
59 59 $ cat $TESTTMP/commandfinish.log | sort
60 60
61 61 0
62 62 commandfinish
63 63 foo
64 64 foo exited 0 after * seconds (glob)
65 65 logtoprocess commandfinish output:
66 66 $ cat $TESTTMP/foo.log | sort
67 67
68 68 a message: spam
69 69 foo
70 70 logtoprocess foo output:
71 71 spam
72 72 #endif
73 73
74 74 Confirm that logging blocked time catches stdio properly:
75 75 $ cp $HGRCPATH.bak $HGRCPATH
76 76 $ cat >> $HGRCPATH << EOF
77 77 > [extensions]
78 78 > logtoprocess=
79 79 > pager=
80 80 > [logtoprocess]
81 81 > uiblocked=echo "\$EVENT stdio \$OPT_STDIO_BLOCKED ms command \$OPT_COMMAND_DURATION ms" > $TESTTMP/uiblocked.log
82 82 > [ui]
83 83 > logblockedtimes=True
84 84 > EOF
85 85
86 86 $ hg log
87 $ sleep 0.2
87 $ sleep 1
88 88 $ cat $TESTTMP/uiblocked.log
89 89 uiblocked stdio [0-9]+.[0-9]* ms command [0-9]+.[0-9]* ms (re)
90 90
91 91 Try to confirm that pager wait on logtoprocess:
92 92
93 93 Add a script that wait on a file to appears for 5 seconds, if it sees it touch
94 94 another file or die after 5 seconds. If the scripts is awaited by hg, the
95 95 script will die after the timeout before we could touch the file and the
96 96 resulting file will not exists. If not, we will touch the file and see it.
97 97
98 98 $ cat > $TESTTMP/wait-output.sh << EOF
99 99 > #!/bin/sh
100 100 > for i in \`$TESTDIR/seq.py 50\`; do
101 101 > if [ -f "$TESTTMP/wait-for-touched" ];
102 102 > then
103 103 > touch "$TESTTMP/touched";
104 104 > break;
105 105 > else
106 106 > sleep 0.1;
107 107 > fi
108 108 > done
109 109 > EOF
110 110 $ chmod +x $TESTTMP/wait-output.sh
111 111
112 112 $ cat >> $HGRCPATH << EOF
113 113 > [extensions]
114 114 > logtoprocess=
115 115 > pager=
116 116 > [logtoprocess]
117 117 > commandfinish=$TESTTMP/wait-output.sh
118 118 > EOF
119 119 $ hg version -q --pager=always
120 120 Mercurial Distributed SCM (version *) (glob)
121 121 $ touch $TESTTMP/wait-for-touched
122 122 $ sleep 0.2
123 123 $ test -f $TESTTMP/touched && echo "SUCCESS Pager is not waiting on ltp" || echo "FAIL Pager is waiting on ltp"
124 124 SUCCESS Pager is not waiting on ltp
General Comments 0
You need to be logged in to leave comments. Login now