Mercurial > hgsubversion
annotate tests/test_pull_fallback.py @ 1233:0d0132cba155
editor: fix edge case with in memory file-store size limit
There are a few cases where we will set a single file into to the
editor's FileStore object more than once. Notably, for copied and
then modified files, we will set it at least twice. Three times if
editing fails (which it can for symlinks).
If we pass the in-memory storage limit in between the first (or second
if editing fails) time we set the file and the last time we set the
file, we will write the data to the in memory store the first time and
the file store the last time. We didn't remove it form the in-memory
store though, and we always prefer reading from the in-memory store.
This means we can sometimes end up with the wrong version of a file.
This is fairly unlikely to happen in normal use since you need to hit
the memory limit between two writes to the store for the same file.
We only write a file multiple times if a) the file (and not one of
it's parent directories) is copied and then modified or b) editing
fails. From what I can tell, it's only common for editing to fail for
symlinks, and they ten to be relatively small data that is unlikely to
push over the limit. Finally, the default limit is 100MB which I
would expect to be most often either well over (source code) or well
under (binaries or automated changes) the size of the changes files in
a single commit.
The easiest way to reproduce this is to set the in-memory cache size
to 0 and then commit a copied and modified symlink. The empty-string
version from the failed editing will be the one that persists. I
happened to stumble upon this while trying (and failing) to test a
bug-fix for a related bug with identical symptoms (empty simlink). I
have seen this in the wild, once, but couldn't reproduce it at the
time. The repo in question is quite large and quite active, so I am
quite confident in my estimation that this is a real, but very rare,
problem.
The test changes attached to this was mneant to test a related bug,
but turned out not to actually cover the bug in question. They did
trigger this bug though, and are worthwhile to test, so I kept them.
author | David Schleimer <dschleimer@fb.com> |
---|---|
date | Mon, 07 Apr 2014 17:51:59 -0700 |
parents | f6c9394032cb |
children | 4f1461428334 |
rev | line source |
---|---|
932
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
1 import test_util |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
2 |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
3 import re |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
4 import mercurial |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
5 from mercurial import commands |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
6 from hgsubversion import stupid |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
7 from hgsubversion import svnwrap |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
8 from hgsubversion import wrappers |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
9 |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
10 class TestPullFallback(test_util.TestBase): |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
11 def setUp(self): |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
12 super(TestPullFallback, self).setUp() |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
13 |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
14 def _loadupdate(self, fixture_name, *args, **kwargs): |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
15 kwargs = kwargs.copy() |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
16 kwargs.update(noupdate=False) |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
17 repo, repo_path = self.load_and_fetch(fixture_name, *args, **kwargs) |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
18 return repo, repo_path |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
19 |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
20 def test_stupid_fallback_to_stupid_fullrevs(self): |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
21 return |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
22 to_patch = { |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
23 'mercurial.patch.patchbackend': _patchbackend_raise, |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
24 'stupid.diff_branchrev': stupid.diff_branchrev, |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
25 'stupid.fetch_branchrev': stupid.fetch_branchrev, |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
26 } |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
27 |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
28 expected_calls = { |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
29 'mercurial.patch.patchbackend': 1, |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
30 'stupid.diff_branchrev': 1, |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
31 'stupid.fetch_branchrev': 1, |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
32 } |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
33 |
1069
f6c9394032cb
test_pull_fallback: use stupid mode metaclass
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
1044
diff
changeset
|
34 self.stupid = True |
f6c9394032cb
test_pull_fallback: use stupid mode metaclass
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
1044
diff
changeset
|
35 repo, repo_path = self._loadupdate('single_rev.svndump') |
f6c9394032cb
test_pull_fallback: use stupid mode metaclass
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
1044
diff
changeset
|
36 self.stupid = False |
932
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
37 |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
38 # Passing stupid=True doesn't seem to be working - force it |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
39 repo.ui.setconfig('hgsubversion', 'stupid', "true") |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
40 state = repo.parents() |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
41 |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
42 calls, replaced = _monkey_patch(to_patch) |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
43 |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
44 try: |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
45 self.add_svn_rev(repo_path, {'trunk/alpha': 'Changed'}) |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
46 commands.pull(self.repo.ui, repo, update=True) |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
47 self.failIfEqual(state, repo.parents()) |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
48 self.assertTrue('tip' in repo[None].tags()) |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
49 self.assertEqual(expected_calls, calls) |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
50 |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
51 finally: |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
52 _monkey_unpatch(replaced) |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
53 |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
54 def _monkey_patch(to_patch, start=None): |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
55 if start is None: |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
56 import sys |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
57 start = sys.modules[__name__] |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
58 |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
59 calls = {} |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
60 replaced = {} |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
61 |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
62 for path, replacement in to_patch.iteritems(): |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
63 obj = start |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
64 owner, attr = path.rsplit('.', 1) |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
65 |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
66 for a in owner.split('.', -1): |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
67 obj = getattr(obj, a) |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
68 |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
69 replaced[path] = getattr(obj, attr) |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
70 calls[path] = 0 |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
71 |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
72 def outer(path=path, calls=calls, replacement=replacement): |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
73 def wrapper(*p, **kw): |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
74 calls[path] += 1 |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
75 return replacement(*p, **kw) |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
76 |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
77 return wrapper |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
78 |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
79 setattr(obj, attr, outer()) |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
80 |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
81 return calls, replaced |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
82 |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
83 def _monkey_unpatch(to_patch, start=None): |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
84 if start is None: |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
85 import sys |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
86 start = sys.modules[__name__] |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
87 |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
88 replaced = {} |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
89 |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
90 for path, replacement in to_patch.iteritems(): |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
91 obj = start |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
92 owner, attr = path.rsplit('.', 1) |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
93 |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
94 for a in owner.split('.', -1): |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
95 obj = getattr(obj, a) |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
96 |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
97 replaced[path] = getattr(obj, attr) |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
98 setattr(obj, attr, replacement) |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
99 |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
100 return replaced |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
101 |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
102 def _patchbackend_raise(*p, **kw): |
dfb3afa6c619
stupid: Fail over to full revision when a PatchError is thrown (issue294)
Tim Delaney <timothy.c.delaney@gmail.com>
parents:
diff
changeset
|
103 raise mercurial.patch.PatchError("patch failed") |