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