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