Mercurial > hg
annotate tests/logexceptions.py @ 44412:edc8504bc26b
exchange: turn on option that makes concurrent pushes work better
The motivation is simply to make hg work better out of the box.
This is a slight backwards compatibility break, because client
extensions could have assumed that the list of heads the client sees
during discovery will be the list of heads during the entirety of the
push. It seems unlikely to matter, and not worth mentioning.
There's a fair amount of diff in tests, but this is just due to
sending a few more bytes on the wire, except for test-acl.t.
The extra "invalid branch cache" lines in test-acl.t don't seem to
indicate a problem: the branchcache now get computed during the bundle
application (because of the check:updated-heads bundle part), but
doesn't get rolled back when transactions rollback, thus causing a
message in the next operation computing the branch cache. Before this
change, I assume the branchcache was only computed on transaction
commit, so not computed at all when the transactions roll back, thus
no messages.
Differential Revision: https://phab.mercurial-scm.org/D8202
author | Valentin Gatien-Baron <valentin.gatienbaron@gmail.com> |
---|---|
date | Tue, 25 Feb 2020 20:27:39 -0500 |
parents | 2372284d9457 |
children | d4ba4d51f85f |
rev | line source |
---|---|
35190
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1 # logexceptions.py - Write files containing info about Mercurial exceptions |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2 # |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3 # Copyright 2017 Matt Mackall <mpm@selenic.com> |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
4 # |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
6 # GNU General Public License version 2 or any later version. |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
7 |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
8 from __future__ import absolute_import |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
9 |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
10 import inspect |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
11 import os |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
12 import sys |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
13 import traceback |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
14 import uuid |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
15 |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
16 from mercurial import ( |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
17 dispatch, |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
18 extensions, |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
19 ) |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
20 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
36037
diff
changeset
|
21 |
35190
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
22 def handleexception(orig, ui): |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
23 res = orig(ui) |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
24 |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
25 if not ui.environ.get(b'HGEXCEPTIONSDIR'): |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
26 return res |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
27 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
36037
diff
changeset
|
28 dest = os.path.join( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
36037
diff
changeset
|
29 ui.environ[b'HGEXCEPTIONSDIR'], str(uuid.uuid4()).encode('ascii') |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
36037
diff
changeset
|
30 ) |
35190
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
31 |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
32 exc_type, exc_value, exc_tb = sys.exc_info() |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
33 |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
34 stack = [] |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
35 tb = exc_tb |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
36 while tb: |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
37 stack.append(tb) |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
38 tb = tb.tb_next |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
39 stack.reverse() |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
40 |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
41 hgframe = 'unknown' |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
42 hgline = 'unknown' |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
43 |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
44 # Find the first Mercurial frame in the stack. |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
45 for tb in stack: |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
46 mod = inspect.getmodule(tb) |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
47 if not mod.__name__.startswith(('hg', 'mercurial')): |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
48 continue |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
49 |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
50 frame = tb.tb_frame |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
51 |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
52 try: |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
53 with open(inspect.getsourcefile(tb), 'r') as fh: |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
54 hgline = fh.readlines()[frame.f_lineno - 1].strip() |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
55 except (IndexError, OSError): |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
56 pass |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
57 |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
58 hgframe = '%s:%d' % (frame.f_code.co_filename, frame.f_lineno) |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
59 break |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
60 |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
61 primary = traceback.extract_tb(exc_tb)[-1] |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
62 primaryframe = '%s:%d' % (primary.filename, primary.lineno) |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
63 |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
64 with open(dest, 'wb') as fh: |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
65 parts = [ |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
66 str(exc_value), |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
67 primaryframe, |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
68 hgframe, |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
69 hgline, |
36037
8de90e006c78
run-tests: report tests that exception occurred in
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35190
diff
changeset
|
70 ui.environ[b'TESTNAME'].decode('utf-8', 'replace'), |
35190
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
71 ] |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
72 fh.write(b'\0'.join(p.encode('utf-8', 'replace') for p in parts)) |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
73 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
36037
diff
changeset
|
74 |
35190
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
75 def extsetup(ui): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
36037
diff
changeset
|
76 extensions.wrapfunction(dispatch, 'handlecommandexception', handleexception) |