##// END OF EJS Templates
py3: add alternate output on Python 3...
Gregory Szorc -
r41584:9955776e default draft
parent child Browse files
Show More
@@ -1,128 +1,130
1 1 Test UI worker interaction
2 2
3 3 $ cat > t.py <<EOF
4 4 > from __future__ import absolute_import, print_function
5 5 > import time
6 6 > from mercurial import (
7 7 > error,
8 8 > registrar,
9 9 > ui as uimod,
10 10 > worker,
11 11 > )
12 12 > def abort(ui, args):
13 13 > if args[0] == 0:
14 14 > # by first worker for test stability
15 15 > raise error.Abort(b'known exception')
16 16 > return runme(ui, [])
17 17 > def exc(ui, args):
18 18 > if args[0] == 0:
19 19 > # by first worker for test stability
20 20 > raise Exception('unknown exception')
21 21 > return runme(ui, [])
22 22 > def runme(ui, args):
23 23 > for arg in args:
24 24 > ui.status(b'run\n')
25 25 > yield 1, arg
26 26 > time.sleep(0.1) # easier to trigger killworkers code path
27 27 > functable = {
28 28 > b'abort': abort,
29 29 > b'exc': exc,
30 30 > b'runme': runme,
31 31 > }
32 32 > cmdtable = {}
33 33 > command = registrar.command(cmdtable)
34 34 > @command(b'test', [], b'hg test [COST] [FUNC]')
35 35 > def t(ui, repo, cost=1.0, func=b'runme'):
36 36 > cost = float(cost)
37 37 > func = functable[func]
38 38 > ui.status(b'start\n')
39 39 > runs = worker.worker(ui, cost, func, (ui,), range(8))
40 40 > for n, i in runs:
41 41 > pass
42 42 > ui.status(b'done\n')
43 43 > EOF
44 44 $ abspath=`pwd`/t.py
45 45 $ hg init
46 46
47 47 Run tests with worker enable by forcing a heigh cost
48 48
49 49 $ hg --config "extensions.t=$abspath" test 100000.0
50 50 start
51 51 run
52 52 run
53 53 run
54 54 run
55 55 run
56 56 run
57 57 run
58 58 run
59 59 done
60 60
61 61 Run tests without worker by forcing a low cost
62 62
63 63 $ hg --config "extensions.t=$abspath" test 0.0000001
64 64 start
65 65 run
66 66 run
67 67 run
68 68 run
69 69 run
70 70 run
71 71 run
72 72 run
73 73 done
74 74
75 75 #if no-windows
76 76
77 77 Known exception should be caught, but printed if --traceback is enabled
78 78
79 79 $ hg --config "extensions.t=$abspath" --config 'worker.numcpus=8' \
80 80 > test 100000.0 abort 2>&1
81 81 start
82 82 abort: known exception
83 83 [255]
84 84
85 85 $ hg --config "extensions.t=$abspath" --config 'worker.numcpus=8' \
86 > test 100000.0 abort --traceback 2>&1 | egrep '^(SystemExit|Abort)'
87 Abort: known exception
86 > test 100000.0 abort --traceback 2>&1 | egrep '(SystemExit|Abort)'
87 raise error.Abort(b'known exception')
88 mercurial.error.Abort: b'known exception' (py3 !)
89 Abort: known exception (no-py3 !)
88 90 SystemExit: 255
89 91
90 92 Traceback must be printed for unknown exceptions
91 93
92 94 $ hg --config "extensions.t=$abspath" --config 'worker.numcpus=8' \
93 95 > test 100000.0 exc 2>&1 | grep '^Exception'
94 96 Exception: unknown exception
95 97
96 98 Workers should not do cleanups in all cases
97 99
98 100 $ cat > $TESTTMP/detectcleanup.py <<EOF
99 101 > from __future__ import absolute_import
100 102 > import atexit
101 103 > import os
102 104 > import time
103 105 > oldfork = os.fork
104 106 > count = 0
105 107 > parentpid = os.getpid()
106 108 > def delayedfork():
107 109 > global count
108 110 > count += 1
109 111 > pid = oldfork()
110 112 > # make it easier to test SIGTERM hitting other workers when they have
111 113 > # not set up error handling yet.
112 114 > if count > 1 and pid == 0:
113 115 > time.sleep(0.1)
114 116 > return pid
115 117 > os.fork = delayedfork
116 118 > def cleanup():
117 119 > if os.getpid() != parentpid:
118 120 > os.write(1, 'should never happen\n')
119 121 > atexit.register(cleanup)
120 122 > EOF
121 123
122 124 $ hg --config "extensions.t=$abspath" --config worker.numcpus=8 --config \
123 125 > "extensions.d=$TESTTMP/detectcleanup.py" test 100000 abort
124 126 start
125 127 abort: known exception
126 128 [255]
127 129
128 130 #endif
General Comments 0
You need to be logged in to leave comments. Login now