annotate tests/test_template_keywords.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 8caf1226adec
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
684
8687c5aa4f35 Add svnrev, svnpath and svnuuid keyword.
Andi Albrecht <albrecht.andi@gmail.com>
parents:
diff changeset
1 import test_util
8687c5aa4f35 Add svnrev, svnpath and svnuuid keyword.
Andi Albrecht <albrecht.andi@gmail.com>
parents:
diff changeset
2
8687c5aa4f35 Add svnrev, svnpath and svnuuid keyword.
Andi Albrecht <albrecht.andi@gmail.com>
parents:
diff changeset
3 import unittest
8687c5aa4f35 Add svnrev, svnpath and svnuuid keyword.
Andi Albrecht <albrecht.andi@gmail.com>
parents:
diff changeset
4
8687c5aa4f35 Add svnrev, svnpath and svnuuid keyword.
Andi Albrecht <albrecht.andi@gmail.com>
parents:
diff changeset
5 from mercurial import commands
722
aa24148a7454 uisetup: add fromsvn() and svnrev() revsets.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 721
diff changeset
6 from mercurial import error
684
8687c5aa4f35 Add svnrev, svnpath and svnuuid keyword.
Andi Albrecht <albrecht.andi@gmail.com>
parents:
diff changeset
7 from mercurial import ui
687
d424bd1ac647 templatekw: restore compatibility with hg < 1.5
Augie Fackler <durin42@gmail.com>
parents: 684
diff changeset
8 try:
d424bd1ac647 templatekw: restore compatibility with hg < 1.5
Augie Fackler <durin42@gmail.com>
parents: 684
diff changeset
9 from mercurial import templatekw
d424bd1ac647 templatekw: restore compatibility with hg < 1.5
Augie Fackler <durin42@gmail.com>
parents: 684
diff changeset
10 templatekw.keywords
d424bd1ac647 templatekw: restore compatibility with hg < 1.5
Augie Fackler <durin42@gmail.com>
parents: 684
diff changeset
11 except ImportError:
d424bd1ac647 templatekw: restore compatibility with hg < 1.5
Augie Fackler <durin42@gmail.com>
parents: 684
diff changeset
12 templatekw = None
684
8687c5aa4f35 Add svnrev, svnpath and svnuuid keyword.
Andi Albrecht <albrecht.andi@gmail.com>
parents:
diff changeset
13
722
aa24148a7454 uisetup: add fromsvn() and svnrev() revsets.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 721
diff changeset
14 try:
aa24148a7454 uisetup: add fromsvn() and svnrev() revsets.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 721
diff changeset
15 from mercurial import revset
aa24148a7454 uisetup: add fromsvn() and svnrev() revsets.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 721
diff changeset
16 revset.methods
aa24148a7454 uisetup: add fromsvn() and svnrev() revsets.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 721
diff changeset
17 except ImportError:
835
f089ca13cc4c test_template_keywords.py: fix indentation of revset except block
Yonggang Luo <luoyonggang@gmail.com>
parents: 833
diff changeset
18 revset = None
684
8687c5aa4f35 Add svnrev, svnpath and svnuuid keyword.
Andi Albrecht <albrecht.andi@gmail.com>
parents:
diff changeset
19
8687c5aa4f35 Add svnrev, svnpath and svnuuid keyword.
Andi Albrecht <albrecht.andi@gmail.com>
parents:
diff changeset
20 class CapturingUI(ui.ui):
8687c5aa4f35 Add svnrev, svnpath and svnuuid keyword.
Andi Albrecht <albrecht.andi@gmail.com>
parents:
diff changeset
21
8687c5aa4f35 Add svnrev, svnpath and svnuuid keyword.
Andi Albrecht <albrecht.andi@gmail.com>
parents:
diff changeset
22 def __init__(self, *args, **kwds):
8687c5aa4f35 Add svnrev, svnpath and svnuuid keyword.
Andi Albrecht <albrecht.andi@gmail.com>
parents:
diff changeset
23 super(CapturingUI, self).__init__(*args, **kwds)
8687c5aa4f35 Add svnrev, svnpath and svnuuid keyword.
Andi Albrecht <albrecht.andi@gmail.com>
parents:
diff changeset
24 self._output = ""
8687c5aa4f35 Add svnrev, svnpath and svnuuid keyword.
Andi Albrecht <albrecht.andi@gmail.com>
parents:
diff changeset
25
8687c5aa4f35 Add svnrev, svnpath and svnuuid keyword.
Andi Albrecht <albrecht.andi@gmail.com>
parents:
diff changeset
26 def write(self, msg, *args, **kwds):
8687c5aa4f35 Add svnrev, svnpath and svnuuid keyword.
Andi Albrecht <albrecht.andi@gmail.com>
parents:
diff changeset
27 self._output += msg
8687c5aa4f35 Add svnrev, svnpath and svnuuid keyword.
Andi Albrecht <albrecht.andi@gmail.com>
parents:
diff changeset
28
721
af817963897e test_template_keywords: use new requiresmodule decorator
Augie Fackler <durin42@gmail.com>
parents: 707
diff changeset
29
707
cb32d90f915e templatekw: clean up implementation & test; add help.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 687
diff changeset
30 class TestLogKeywords(test_util.TestBase):
721
af817963897e test_template_keywords: use new requiresmodule decorator
Augie Fackler <durin42@gmail.com>
parents: 707
diff changeset
31 @test_util.requiresmodule(templatekw)
af817963897e test_template_keywords: use new requiresmodule decorator
Augie Fackler <durin42@gmail.com>
parents: 707
diff changeset
32 def test_svn_keywords(self):
1177
8caf1226adec test_template_keywords: handle changeset output ordering change in hg 3.0
Augie Fackler <raf@durin42.com>
parents: 1044
diff changeset
33 defaults = {'date': None, 'rev': None, 'user': None, 'graph': True}
721
af817963897e test_template_keywords: use new requiresmodule decorator
Augie Fackler <durin42@gmail.com>
parents: 707
diff changeset
34 repo = self._load_fixture_and_fetch('two_revs.svndump')
af817963897e test_template_keywords: use new requiresmodule decorator
Augie Fackler <durin42@gmail.com>
parents: 707
diff changeset
35
af817963897e test_template_keywords: use new requiresmodule decorator
Augie Fackler <durin42@gmail.com>
parents: 707
diff changeset
36 # we want one commit that isn't from Subversion
af817963897e test_template_keywords: use new requiresmodule decorator
Augie Fackler <durin42@gmail.com>
parents: 707
diff changeset
37 self.commitchanges([('foo', 'foo', 'frobnicate\n')])
af817963897e test_template_keywords: use new requiresmodule decorator
Augie Fackler <durin42@gmail.com>
parents: 707
diff changeset
38
af817963897e test_template_keywords: use new requiresmodule decorator
Augie Fackler <durin42@gmail.com>
parents: 707
diff changeset
39 ui = CapturingUI()
1177
8caf1226adec test_template_keywords: handle changeset output ordering change in hg 3.0
Augie Fackler <raf@durin42.com>
parents: 1044
diff changeset
40 commands.log(ui, repo, template=(' rev: {rev} svnrev:{svnrev} '
8caf1226adec test_template_keywords: handle changeset output ordering change in hg 3.0
Augie Fackler <raf@durin42.com>
parents: 1044
diff changeset
41 'svnpath:{svnpath} svnuuid:{svnuuid}\n'),
8caf1226adec test_template_keywords: handle changeset output ordering change in hg 3.0
Augie Fackler <raf@durin42.com>
parents: 1044
diff changeset
42 **defaults)
8caf1226adec test_template_keywords: handle changeset output ordering change in hg 3.0
Augie Fackler <raf@durin42.com>
parents: 1044
diff changeset
43 print ui._output
8caf1226adec test_template_keywords: handle changeset output ordering change in hg 3.0
Augie Fackler <raf@durin42.com>
parents: 1044
diff changeset
44 self.assertEqual(ui._output.strip(), '''
8caf1226adec test_template_keywords: handle changeset output ordering change in hg 3.0
Augie Fackler <raf@durin42.com>
parents: 1044
diff changeset
45 rev: 2 svnrev: svnpath: svnuuid:
8caf1226adec test_template_keywords: handle changeset output ordering change in hg 3.0
Augie Fackler <raf@durin42.com>
parents: 1044
diff changeset
46 @
8caf1226adec test_template_keywords: handle changeset output ordering change in hg 3.0
Augie Fackler <raf@durin42.com>
parents: 1044
diff changeset
47 |
8caf1226adec test_template_keywords: handle changeset output ordering change in hg 3.0
Augie Fackler <raf@durin42.com>
parents: 1044
diff changeset
48 rev: 1 svnrev:3 svnpath:/trunk svnuuid:df2126f7-00ab-4d49-b42c-7e981dde0bcf
8caf1226adec test_template_keywords: handle changeset output ordering change in hg 3.0
Augie Fackler <raf@durin42.com>
parents: 1044
diff changeset
49 o
8caf1226adec test_template_keywords: handle changeset output ordering change in hg 3.0
Augie Fackler <raf@durin42.com>
parents: 1044
diff changeset
50 |
8caf1226adec test_template_keywords: handle changeset output ordering change in hg 3.0
Augie Fackler <raf@durin42.com>
parents: 1044
diff changeset
51 rev: 0 svnrev:2 svnpath:/trunk svnuuid:df2126f7-00ab-4d49-b42c-7e981dde0bcf
8caf1226adec test_template_keywords: handle changeset output ordering change in hg 3.0
Augie Fackler <raf@durin42.com>
parents: 1044
diff changeset
52 o
8caf1226adec test_template_keywords: handle changeset output ordering change in hg 3.0
Augie Fackler <raf@durin42.com>
parents: 1044
diff changeset
53 '''.strip())
687
d424bd1ac647 templatekw: restore compatibility with hg < 1.5
Augie Fackler <durin42@gmail.com>
parents: 684
diff changeset
54
723
4baa41e0f8ad revset tests: use requiresmodule decorator
Augie Fackler <durin42@gmail.com>
parents: 722
diff changeset
55 @test_util.requiresmodule(revset)
4baa41e0f8ad revset tests: use requiresmodule decorator
Augie Fackler <durin42@gmail.com>
parents: 722
diff changeset
56 @test_util.requiresmodule(templatekw)
4baa41e0f8ad revset tests: use requiresmodule decorator
Augie Fackler <durin42@gmail.com>
parents: 722
diff changeset
57 def test_svn_revsets(self):
4baa41e0f8ad revset tests: use requiresmodule decorator
Augie Fackler <durin42@gmail.com>
parents: 722
diff changeset
58 repo = self._load_fixture_and_fetch('two_revs.svndump')
722
aa24148a7454 uisetup: add fromsvn() and svnrev() revsets.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 721
diff changeset
59
723
4baa41e0f8ad revset tests: use requiresmodule decorator
Augie Fackler <durin42@gmail.com>
parents: 722
diff changeset
60 # we want one commit that isn't from Subversion
4baa41e0f8ad revset tests: use requiresmodule decorator
Augie Fackler <durin42@gmail.com>
parents: 722
diff changeset
61 self.commitchanges([('foo', 'foo', 'frobnicate\n')])
722
aa24148a7454 uisetup: add fromsvn() and svnrev() revsets.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 721
diff changeset
62
723
4baa41e0f8ad revset tests: use requiresmodule decorator
Augie Fackler <durin42@gmail.com>
parents: 722
diff changeset
63 defaults = {'date': None, 'rev': ['fromsvn()'], 'user': None}
722
aa24148a7454 uisetup: add fromsvn() and svnrev() revsets.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 721
diff changeset
64
723
4baa41e0f8ad revset tests: use requiresmodule decorator
Augie Fackler <durin42@gmail.com>
parents: 722
diff changeset
65 ui = CapturingUI()
4baa41e0f8ad revset tests: use requiresmodule decorator
Augie Fackler <durin42@gmail.com>
parents: 722
diff changeset
66 commands.log(ui, repo, template='{rev}:{svnrev} ', **defaults)
4baa41e0f8ad revset tests: use requiresmodule decorator
Augie Fackler <durin42@gmail.com>
parents: 722
diff changeset
67 self.assertEqual(ui._output, '0:2 1:3 ')
722
aa24148a7454 uisetup: add fromsvn() and svnrev() revsets.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 721
diff changeset
68
723
4baa41e0f8ad revset tests: use requiresmodule decorator
Augie Fackler <durin42@gmail.com>
parents: 722
diff changeset
69 defaults = {'date': None, 'rev': ['svnrev(2)'], 'user': None}
722
aa24148a7454 uisetup: add fromsvn() and svnrev() revsets.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 721
diff changeset
70
723
4baa41e0f8ad revset tests: use requiresmodule decorator
Augie Fackler <durin42@gmail.com>
parents: 722
diff changeset
71 ui = CapturingUI()
4baa41e0f8ad revset tests: use requiresmodule decorator
Augie Fackler <durin42@gmail.com>
parents: 722
diff changeset
72 commands.log(ui, repo, template='{rev}:{svnrev} ', **defaults)
4baa41e0f8ad revset tests: use requiresmodule decorator
Augie Fackler <durin42@gmail.com>
parents: 722
diff changeset
73 self.assertEqual(ui._output, '0:2 ')
722
aa24148a7454 uisetup: add fromsvn() and svnrev() revsets.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 721
diff changeset
74
723
4baa41e0f8ad revset tests: use requiresmodule decorator
Augie Fackler <durin42@gmail.com>
parents: 722
diff changeset
75 defaults = {'date': None, 'rev': ['fromsvn(1)'], 'user': None}
722
aa24148a7454 uisetup: add fromsvn() and svnrev() revsets.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 721
diff changeset
76
723
4baa41e0f8ad revset tests: use requiresmodule decorator
Augie Fackler <durin42@gmail.com>
parents: 722
diff changeset
77 self.assertRaises(error.ParseError,
4baa41e0f8ad revset tests: use requiresmodule decorator
Augie Fackler <durin42@gmail.com>
parents: 722
diff changeset
78 commands.log, self.ui(), repo,
4baa41e0f8ad revset tests: use requiresmodule decorator
Augie Fackler <durin42@gmail.com>
parents: 722
diff changeset
79 template='{rev}:{svnrev} ', **defaults)
722
aa24148a7454 uisetup: add fromsvn() and svnrev() revsets.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 721
diff changeset
80
723
4baa41e0f8ad revset tests: use requiresmodule decorator
Augie Fackler <durin42@gmail.com>
parents: 722
diff changeset
81 defaults = {'date': None, 'rev': ['svnrev(1, 2)'], 'user': None}
722
aa24148a7454 uisetup: add fromsvn() and svnrev() revsets.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 721
diff changeset
82
723
4baa41e0f8ad revset tests: use requiresmodule decorator
Augie Fackler <durin42@gmail.com>
parents: 722
diff changeset
83 self.assertRaises(error.ParseError,
4baa41e0f8ad revset tests: use requiresmodule decorator
Augie Fackler <durin42@gmail.com>
parents: 722
diff changeset
84 commands.log, self.ui(), repo,
4baa41e0f8ad revset tests: use requiresmodule decorator
Augie Fackler <durin42@gmail.com>
parents: 722
diff changeset
85 template='{rev}:{svnrev} ', **defaults)