annotate tests/test_single_dir_clone.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 6e1dbf6cbc92
children a36e87ae2380
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
643
d2ef7220a079 tests: import test_util as the first module in all relevant tests
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 577
diff changeset
1 import test_util
d2ef7220a079 tests: import test_util as the first module in all relevant tests
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 577
diff changeset
2
531
cf4fe45bf8fd Change all instantiations of IOError to set both errno and strerror.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 502
diff changeset
3 import errno
499
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
4 import shutil
577
930bb6df19a0 tests: make sure single dir clone tests get run by non-nose users
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 531
diff changeset
5 import unittest
499
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
6
500
5ddc212dbc56 push: fix for single directory repository layouts
Daniel Tang <dytang@cs.purdue.edu>
parents: 499
diff changeset
7 from mercurial import commands
5ddc212dbc56 push: fix for single directory repository layouts
Daniel Tang <dytang@cs.purdue.edu>
parents: 499
diff changeset
8 from mercurial import context
5ddc212dbc56 push: fix for single directory repository layouts
Daniel Tang <dytang@cs.purdue.edu>
parents: 499
diff changeset
9 from mercurial import hg
5ddc212dbc56 push: fix for single directory repository layouts
Daniel Tang <dytang@cs.purdue.edu>
parents: 499
diff changeset
10 from mercurial import node
5ddc212dbc56 push: fix for single directory repository layouts
Daniel Tang <dytang@cs.purdue.edu>
parents: 499
diff changeset
11 from mercurial import ui
5ddc212dbc56 push: fix for single directory repository layouts
Daniel Tang <dytang@cs.purdue.edu>
parents: 499
diff changeset
12
1103
6e1dbf6cbc92 compathacks: new module to collect hacks to work around hg internals changing
Augie Fackler <raf@durin42.com>
parents: 1074
diff changeset
13 from hgsubversion import compathacks
6e1dbf6cbc92 compathacks: new module to collect hacks to work around hg internals changing
Augie Fackler <raf@durin42.com>
parents: 1074
diff changeset
14
1047
3092b3c109a8 tests: split single directory tests that push & clone in two modules
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 1044
diff changeset
15 class TestSingleDirClone(test_util.TestBase):
1074
2668785264d7 test_single_dir_clone: use stupid mode metaclass
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 1047
diff changeset
16 stupid_mode_tests = True
2668785264d7 test_single_dir_clone: use stupid mode metaclass
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 1047
diff changeset
17
499
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
18 def test_clone_single_dir_simple(self):
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
19 repo = self._load_fixture_and_fetch('branch_from_tag.svndump',
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
20 layout='single',
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
21 subdir='')
1103
6e1dbf6cbc92 compathacks: new module to collect hacks to work around hg internals changing
Augie Fackler <raf@durin42.com>
parents: 1074
diff changeset
22 self.assertEqual(compathacks.branchset(repo),
6e1dbf6cbc92 compathacks: new module to collect hacks to work around hg internals changing
Augie Fackler <raf@durin42.com>
parents: 1074
diff changeset
23 set(['default']))
499
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
24 self.assertEqual(repo['tip'].manifest().keys(),
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
25 ['trunk/beta',
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
26 'tags/copied_tag/alpha',
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
27 'trunk/alpha',
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
28 'tags/copied_tag/beta',
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
29 'branches/branch_from_tag/alpha',
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
30 'tags/tag_r3/alpha',
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
31 'tags/tag_r3/beta',
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
32 'branches/branch_from_tag/beta'])
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
33
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
34 def test_auto_detect_single(self):
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
35 repo = self._load_fixture_and_fetch('branch_from_tag.svndump',
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
36 layout='auto')
1103
6e1dbf6cbc92 compathacks: new module to collect hacks to work around hg internals changing
Augie Fackler <raf@durin42.com>
parents: 1074
diff changeset
37 self.assertEqual(compathacks.branchset(repo),
6e1dbf6cbc92 compathacks: new module to collect hacks to work around hg internals changing
Augie Fackler <raf@durin42.com>
parents: 1074
diff changeset
38 set(['default', 'branch_from_tag']))
499
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
39 oldmanifest = test_util.filtermanifest(repo['default'].manifest().keys())
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
40 # remove standard layout
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
41 shutil.rmtree(self.wc_path)
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
42 # try again with subdir to get single dir clone
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
43 repo = self._load_fixture_and_fetch('branch_from_tag.svndump',
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
44 layout='auto',
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
45 subdir='trunk')
1103
6e1dbf6cbc92 compathacks: new module to collect hacks to work around hg internals changing
Augie Fackler <raf@durin42.com>
parents: 1074
diff changeset
46 self.assertEqual(compathacks.branchset(repo), set(['default', ]))
499
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
47 self.assertEqual(repo['default'].manifest().keys(), oldmanifest)
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
48
1074
2668785264d7 test_single_dir_clone: use stupid mode metaclass
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 1047
diff changeset
49 def test_clone_subdir_is_file_prefix(self):
888
c6388ed0ec0a svnmeta: only remove directory components in normalize()
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 871
diff changeset
50 FIXTURE = 'subdir_is_file_prefix.svndump'
c6388ed0ec0a svnmeta: only remove directory components in normalize()
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 871
diff changeset
51 repo = self._load_fixture_and_fetch(FIXTURE,
c6388ed0ec0a svnmeta: only remove directory components in normalize()
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 871
diff changeset
52 layout='single',
c6388ed0ec0a svnmeta: only remove directory components in normalize()
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 871
diff changeset
53 subdir=test_util.subdir[FIXTURE])
1103
6e1dbf6cbc92 compathacks: new module to collect hacks to work around hg internals changing
Augie Fackler <raf@durin42.com>
parents: 1074
diff changeset
54 self.assertEqual(compathacks.branchset(repo), set(['default']))
888
c6388ed0ec0a svnmeta: only remove directory components in normalize()
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 871
diff changeset
55 self.assertEqual(repo['tip'].manifest().keys(), ['flaf.txt'])
c6388ed0ec0a svnmeta: only remove directory components in normalize()
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents: 871
diff changeset
56
499
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
57 def test_externals_single(self):
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
58 repo = self._load_fixture_and_fetch('externals.svndump',
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
59 layout='single')
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
60 for rev in repo:
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
61 assert '.hgsvnexternals' not in repo[rev].manifest()
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
62 return # TODO enable test when externals in single are fixed
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
63 expect = """[.]
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
64 -r2 ^/externals/project2@2 deps/project2
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
65 [subdir]
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
66 ^/externals/project1 deps/project1
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
67 [subdir2]
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
68 ^/externals/project1 deps/project1
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
69 """
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
70 test = 2
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
71 self.assertEqual(self.repo[test]['.hgsvnexternals'].data(), expect)
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
72
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
73 def test_externals_single_whole_repo(self):
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
74 # This is the test which demonstrates the brokenness of externals
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
75 return # TODO enable test when externals in single are fixed
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
76 repo = self._load_fixture_and_fetch('externals.svndump',
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
77 layout='single',
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
78 subdir='')
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
79 for rev in repo:
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
80 rc = repo[rev]
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
81 if '.hgsvnexternals' in rc:
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
82 extdata = rc['.hgsvnexternals'].data()
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
83 assert '[.]' not in extdata
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
84 print extdata
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
85 expect = '' # Not honestly sure what this should be...
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
86 test = 4
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
87 self.assertEqual(self.repo[test]['.hgsvnexternals'].data(), expect)