Mercurial > hg
annotate tests/flagprocessorext.py @ 31971:73e9328e5307
obsolescence: add test case D-3 for obsolescence markers exchange
About 3 years ago, in August 2014, the logic to select what markers to select on
push was ported from the evolve extension to Mercurial core. However, for some
unclear reasons, the tests for that logic were not ported alongside.
I realised it a couple of weeks ago while working on another push related issue.
I've made a clean up pass on the tests and they are now ready to integrate the
core test suite. This series of changesets do not change any logic. I just adds
test for logic that has been around for about 10 versions of Mercurial.
They are a patch for each test case. It makes it easier to review and postpone
one with documentation issues without rejecting the wholes series.
This patch introduce case D3: missing prune target (prune not in "pushed set")
Each test case comes it in own test file. It help parallelism and does not
introduce a significant overhead from having a single unified giant test file.
Here are timing to support this claim.
# Multiple test files version:
# run-tests.py --local -j 1 test-exchange-*.t
53.40s user 6.82s system 85% cpu 1:10.76 total
52.79s user 6.97s system 85% cpu 1:09.97 total
52.94s user 6.82s system 85% cpu 1:09.69 total
# Single test file version:
# run-tests.py --local -j 1 test-exchange-obsmarkers.t
52.97s user 6.85s system 85% cpu 1:10.10 total
52.64s user 6.79s system 85% cpu 1:09.63 total
53.70s user 7.00s system 85% cpu 1:11.17 total
author | Pierre-Yves David <pierre-yves.david@ens-lyon.org> |
---|---|
date | Mon, 10 Apr 2017 16:54:43 +0200 |
parents | 77f746e5383a |
children | 3e3f4c03876b |
rev | line source |
---|---|
30745 | 1 # coding=UTF-8 |
2 | |
3 from __future__ import absolute_import | |
4 | |
5 import base64 | |
6 import zlib | |
7 | |
8 from mercurial import ( | |
9 changegroup, | |
31832
77f746e5383a
test-flagprocessor: use changegroup3 in bundle2
Jun Wu <quark@fb.com>
parents:
30745
diff
changeset
|
10 exchange, |
30745 | 11 extensions, |
12 filelog, | |
13 revlog, | |
14 util, | |
15 ) | |
16 | |
17 # Test only: These flags are defined here only in the context of testing the | |
18 # behavior of the flag processor. The canonical way to add flags is to get in | |
19 # touch with the community and make them known in revlog. | |
20 REVIDX_NOOP = (1 << 3) | |
21 REVIDX_BASE64 = (1 << 2) | |
22 REVIDX_GZIP = (1 << 1) | |
23 REVIDX_FAIL = 1 | |
24 | |
25 def validatehash(self, text): | |
26 return True | |
27 | |
28 def bypass(self, text): | |
29 return False | |
30 | |
31 def noopdonothing(self, text): | |
32 return (text, True) | |
33 | |
34 def b64encode(self, text): | |
35 return (base64.b64encode(text), False) | |
36 | |
37 def b64decode(self, text): | |
38 return (base64.b64decode(text), True) | |
39 | |
40 def gzipcompress(self, text): | |
41 return (zlib.compress(text), False) | |
42 | |
43 def gzipdecompress(self, text): | |
44 return (zlib.decompress(text), True) | |
45 | |
46 def supportedoutgoingversions(orig, repo): | |
47 versions = orig(repo) | |
48 versions.discard('01') | |
49 versions.discard('02') | |
50 versions.add('03') | |
51 return versions | |
52 | |
53 def allsupportedversions(orig, ui): | |
54 versions = orig(ui) | |
55 versions.add('03') | |
56 return versions | |
57 | |
58 def noopaddrevision(orig, self, text, transaction, link, p1, p2, | |
59 cachedelta=None, node=None, | |
60 flags=revlog.REVIDX_DEFAULT_FLAGS): | |
61 if '[NOOP]' in text: | |
62 flags |= REVIDX_NOOP | |
63 return orig(self, text, transaction, link, p1, p2, cachedelta=cachedelta, | |
64 node=node, flags=flags) | |
65 | |
66 def b64addrevision(orig, self, text, transaction, link, p1, p2, | |
67 cachedelta=None, node=None, | |
68 flags=revlog.REVIDX_DEFAULT_FLAGS): | |
69 if '[BASE64]' in text: | |
70 flags |= REVIDX_BASE64 | |
71 return orig(self, text, transaction, link, p1, p2, cachedelta=cachedelta, | |
72 node=node, flags=flags) | |
73 | |
74 def gzipaddrevision(orig, self, text, transaction, link, p1, p2, | |
75 cachedelta=None, node=None, | |
76 flags=revlog.REVIDX_DEFAULT_FLAGS): | |
77 if '[GZIP]' in text: | |
78 flags |= REVIDX_GZIP | |
79 return orig(self, text, transaction, link, p1, p2, cachedelta=cachedelta, | |
80 node=node, flags=flags) | |
81 | |
82 def failaddrevision(orig, self, text, transaction, link, p1, p2, | |
83 cachedelta=None, node=None, | |
84 flags=revlog.REVIDX_DEFAULT_FLAGS): | |
85 # This addrevision wrapper is meant to add a flag we will not have | |
86 # transforms registered for, ensuring we handle this error case. | |
87 if '[FAIL]' in text: | |
88 flags |= REVIDX_FAIL | |
89 return orig(self, text, transaction, link, p1, p2, cachedelta=cachedelta, | |
90 node=node, flags=flags) | |
91 | |
92 def extsetup(ui): | |
93 # Enable changegroup3 for flags to be sent over the wire | |
94 wrapfunction = extensions.wrapfunction | |
95 wrapfunction(changegroup, | |
96 'supportedoutgoingversions', | |
97 supportedoutgoingversions) | |
98 wrapfunction(changegroup, | |
99 'allsupportedversions', | |
100 allsupportedversions) | |
101 | |
102 # Teach revlog about our test flags | |
103 flags = [REVIDX_NOOP, REVIDX_BASE64, REVIDX_GZIP, REVIDX_FAIL] | |
104 revlog.REVIDX_KNOWN_FLAGS |= util.bitsfrom(flags) | |
105 revlog.REVIDX_FLAGS_ORDER.extend(flags) | |
106 | |
31832
77f746e5383a
test-flagprocessor: use changegroup3 in bundle2
Jun Wu <quark@fb.com>
parents:
30745
diff
changeset
|
107 # Teach exchange to use changegroup 3 |
77f746e5383a
test-flagprocessor: use changegroup3 in bundle2
Jun Wu <quark@fb.com>
parents:
30745
diff
changeset
|
108 for k in exchange._bundlespeccgversions.keys(): |
77f746e5383a
test-flagprocessor: use changegroup3 in bundle2
Jun Wu <quark@fb.com>
parents:
30745
diff
changeset
|
109 exchange._bundlespeccgversions[k] = '03' |
77f746e5383a
test-flagprocessor: use changegroup3 in bundle2
Jun Wu <quark@fb.com>
parents:
30745
diff
changeset
|
110 |
30745 | 111 # Add wrappers for addrevision, responsible to set flags depending on the |
112 # revision data contents. | |
113 wrapfunction(filelog.filelog, 'addrevision', noopaddrevision) | |
114 wrapfunction(filelog.filelog, 'addrevision', b64addrevision) | |
115 wrapfunction(filelog.filelog, 'addrevision', gzipaddrevision) | |
116 wrapfunction(filelog.filelog, 'addrevision', failaddrevision) | |
117 | |
118 # Register flag processors for each extension | |
119 revlog.addflagprocessor( | |
120 REVIDX_NOOP, | |
121 ( | |
122 noopdonothing, | |
123 noopdonothing, | |
124 validatehash, | |
125 ) | |
126 ) | |
127 revlog.addflagprocessor( | |
128 REVIDX_BASE64, | |
129 ( | |
130 b64decode, | |
131 b64encode, | |
132 bypass, | |
133 ), | |
134 ) | |
135 revlog.addflagprocessor( | |
136 REVIDX_GZIP, | |
137 ( | |
138 gzipdecompress, | |
139 gzipcompress, | |
140 bypass | |
141 ) | |
142 ) |