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