annotate tests/test-lrucachedict.py @ 29196:bf7b8157c483 stable

strip: invalidate phase cache after stripping changeset (issue5235) When we remove a changeset from the changelog, the phase cache must be invalidated, otherwise it could refer to changesets that are no longer in the repo. To reproduce the failure, I created an extension querying the phase cache after the strip transaction is over. To do that, I stripped two commits with a bookmark on one of them to force another transaction (we open a transaction for moving bookmarks) after the strip transaction. Without the fix in this patch, the test leads to a stacktrace showing the issue: repair.strip(ui, repo, revs, backup) File "/Users/lcharignon/facebook-hg-rpms/hg-crew/mercurial/repair.py", line 205, in strip tr.close() File "/Users/lcharignon/facebook-hg-rpms/hg-crew/mercurial/transaction.py", line 44, in _active return func(self, *args, **kwds) File "/Users/lcharignon/facebook-hg-rpms/hg-crew/mercurial/transaction.py", line 490, in close self._postclosecallback[cat](self) File "$TESTTMP/crashstrip2.py", line 4, in test [repo.changelog.node(r) for r in repo.revs("not public()")] File "/Users/lcharignon/facebook-hg-rpms/hg-crew/mercurial/changelog.py", line 337, in node return super(changelog, self).node(rev) File "/Users/lcharignon/facebook-hg-rpms/hg-crew/mercurial/revlog.py", line 377, in node return self.index[rev][7] IndexError: revlog index out of range The situation was encountered in inhibit (evolve's repo) where we would crash following the volatile set invalidation submitted by Augie in e6f490e328635312ee214a12bc7fd3c7d46bf9ce. Before his patch the issue was masked as we were not accessing the phasecache after stripping a revision. This bug uncovered another but in histedit (see explanation in issue5235). I changed the histedit test accordingly to avoid fixing two things at once.
author Laurent Charignon <lcharignon@fb.com>
date Thu, 12 May 2016 06:13:59 -0700
parents ba0e4789bd2e
children 79add5a4e857
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
28931
ba0e4789bd2e tests: make test-lrucachedict use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28930
diff changeset
1 from __future__ import absolute_import, print_function
28930
e3f01188d439 tests: make test-lrucachedict use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27576
diff changeset
2
e3f01188d439 tests: make test-lrucachedict use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27576
diff changeset
3 from mercurial import (
e3f01188d439 tests: make test-lrucachedict use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27576
diff changeset
4 util,
e3f01188d439 tests: make test-lrucachedict use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27576
diff changeset
5 )
18603
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
6
27576
6cd3044985c2 lrucachedict: add copy method
Eric Sumner <ericsumner@fb.com>
parents: 27371
diff changeset
7 def printifpresent(d, xs, name='d'):
18603
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
8 for x in xs:
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
9 present = x in d
28931
ba0e4789bd2e tests: make test-lrucachedict use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28930
diff changeset
10 print("'%s' in %s: %s" % (x, name, present))
18603
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
11 if present:
28931
ba0e4789bd2e tests: make test-lrucachedict use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28930
diff changeset
12 print("%s['%s']: %s" % (name, x, d[x]))
18603
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
13
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
14 def test_lrucachedict():
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
15 d = util.lrucachedict(4)
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
16 d['a'] = 'va'
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
17 d['b'] = 'vb'
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
18 d['c'] = 'vc'
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
19 d['d'] = 'vd'
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
20
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
21 # all of these should be present
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
22 printifpresent(d, ['a', 'b', 'c', 'd'])
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
23
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
24 # 'a' should be dropped because it was least recently used
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
25 d['e'] = 've'
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
26 printifpresent(d, ['a', 'b', 'c', 'd', 'e'])
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
27
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
28 # touch entries in some order (get or set).
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
29 d['e']
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
30 d['c'] = 'vc2'
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
31 d['d']
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
32 d['b'] = 'vb2'
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
33
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
34 # 'e' should be dropped now
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
35 d['f'] = 'vf'
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
36 printifpresent(d, ['b', 'c', 'd', 'e', 'f'])
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
37
19710
887ffa22fd0d lrucachedict: implement clear()
Siddharth Agarwal <sid0@fb.com>
parents: 18603
diff changeset
38 d.clear()
887ffa22fd0d lrucachedict: implement clear()
Siddharth Agarwal <sid0@fb.com>
parents: 18603
diff changeset
39 printifpresent(d, ['b', 'c', 'd', 'e', 'f'])
887ffa22fd0d lrucachedict: implement clear()
Siddharth Agarwal <sid0@fb.com>
parents: 18603
diff changeset
40
27371
45d996a566d7 util: reimplement lrucachedict
Gregory Szorc <gregory.szorc@gmail.com>
parents: 19710
diff changeset
41 # Now test dicts that aren't full.
45d996a566d7 util: reimplement lrucachedict
Gregory Szorc <gregory.szorc@gmail.com>
parents: 19710
diff changeset
42 d = util.lrucachedict(4)
45d996a566d7 util: reimplement lrucachedict
Gregory Szorc <gregory.szorc@gmail.com>
parents: 19710
diff changeset
43 d['a'] = 1
45d996a566d7 util: reimplement lrucachedict
Gregory Szorc <gregory.szorc@gmail.com>
parents: 19710
diff changeset
44 d['b'] = 2
45d996a566d7 util: reimplement lrucachedict
Gregory Szorc <gregory.szorc@gmail.com>
parents: 19710
diff changeset
45 d['a']
45d996a566d7 util: reimplement lrucachedict
Gregory Szorc <gregory.szorc@gmail.com>
parents: 19710
diff changeset
46 d['b']
45d996a566d7 util: reimplement lrucachedict
Gregory Szorc <gregory.szorc@gmail.com>
parents: 19710
diff changeset
47 printifpresent(d, ['a', 'b'])
45d996a566d7 util: reimplement lrucachedict
Gregory Szorc <gregory.szorc@gmail.com>
parents: 19710
diff changeset
48
27576
6cd3044985c2 lrucachedict: add copy method
Eric Sumner <ericsumner@fb.com>
parents: 27371
diff changeset
49 # test copy method
6cd3044985c2 lrucachedict: add copy method
Eric Sumner <ericsumner@fb.com>
parents: 27371
diff changeset
50 d = util.lrucachedict(4)
6cd3044985c2 lrucachedict: add copy method
Eric Sumner <ericsumner@fb.com>
parents: 27371
diff changeset
51 d['a'] = 'va3'
6cd3044985c2 lrucachedict: add copy method
Eric Sumner <ericsumner@fb.com>
parents: 27371
diff changeset
52 d['b'] = 'vb3'
6cd3044985c2 lrucachedict: add copy method
Eric Sumner <ericsumner@fb.com>
parents: 27371
diff changeset
53 d['c'] = 'vc3'
6cd3044985c2 lrucachedict: add copy method
Eric Sumner <ericsumner@fb.com>
parents: 27371
diff changeset
54 d['d'] = 'vd3'
6cd3044985c2 lrucachedict: add copy method
Eric Sumner <ericsumner@fb.com>
parents: 27371
diff changeset
55
6cd3044985c2 lrucachedict: add copy method
Eric Sumner <ericsumner@fb.com>
parents: 27371
diff changeset
56 dc = d.copy()
6cd3044985c2 lrucachedict: add copy method
Eric Sumner <ericsumner@fb.com>
parents: 27371
diff changeset
57
6cd3044985c2 lrucachedict: add copy method
Eric Sumner <ericsumner@fb.com>
parents: 27371
diff changeset
58 # all of these should be present
28931
ba0e4789bd2e tests: make test-lrucachedict use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28930
diff changeset
59 print("\nAll of these should be present:")
27576
6cd3044985c2 lrucachedict: add copy method
Eric Sumner <ericsumner@fb.com>
parents: 27371
diff changeset
60 printifpresent(dc, ['a', 'b', 'c', 'd'], 'dc')
6cd3044985c2 lrucachedict: add copy method
Eric Sumner <ericsumner@fb.com>
parents: 27371
diff changeset
61
6cd3044985c2 lrucachedict: add copy method
Eric Sumner <ericsumner@fb.com>
parents: 27371
diff changeset
62 # 'a' should be dropped because it was least recently used
28931
ba0e4789bd2e tests: make test-lrucachedict use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28930
diff changeset
63 print("\nAll of these except 'a' should be present:")
27576
6cd3044985c2 lrucachedict: add copy method
Eric Sumner <ericsumner@fb.com>
parents: 27371
diff changeset
64 dc['e'] = 've3'
6cd3044985c2 lrucachedict: add copy method
Eric Sumner <ericsumner@fb.com>
parents: 27371
diff changeset
65 printifpresent(dc, ['a', 'b', 'c', 'd', 'e'], 'dc')
6cd3044985c2 lrucachedict: add copy method
Eric Sumner <ericsumner@fb.com>
parents: 27371
diff changeset
66
6cd3044985c2 lrucachedict: add copy method
Eric Sumner <ericsumner@fb.com>
parents: 27371
diff changeset
67 # contents and order of original dict should remain unchanged
28931
ba0e4789bd2e tests: make test-lrucachedict use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28930
diff changeset
68 print("\nThese should be in reverse alphabetical order and read 'v?3':")
27576
6cd3044985c2 lrucachedict: add copy method
Eric Sumner <ericsumner@fb.com>
parents: 27371
diff changeset
69 dc['b'] = 'vb3_new'
6cd3044985c2 lrucachedict: add copy method
Eric Sumner <ericsumner@fb.com>
parents: 27371
diff changeset
70 for k in list(iter(d)):
28931
ba0e4789bd2e tests: make test-lrucachedict use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28930
diff changeset
71 print("d['%s']: %s" % (k, d[k]))
27576
6cd3044985c2 lrucachedict: add copy method
Eric Sumner <ericsumner@fb.com>
parents: 27371
diff changeset
72
18603
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
73 if __name__ == '__main__':
2251b3184e6e util: add an LRU cache dict
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
74 test_lrucachedict()