annotate tests/comprehensive/test_sqlite_revmap.py @ 1475:ea4d6142c6d9

maps: do not ask sqlite for row count "SELECT COUNT(1) FROM x" is not O(1) for sqlite and can be slow on large tables. This patch changes the count to be backed by a file instead. The change exposes a risk that the number may become inaccurate, if __setitem__ is called with a same key multiple times. But we don't do that during pull, and only use __len__ to calculate how many revisions pulled, or test if the map is empty. So it would be fine.
author Jun Wu <quark@fb.com>
date Thu, 23 Jun 2016 10:46:07 +0100
parents f21605bcda24
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1474
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
1 import os
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
2 import unittest
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
3 import sys
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
4
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
5 # wrapped in a try/except because of weirdness in how
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
6 # run.py works as compared to nose.
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
7 try:
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
8 import test_util
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
9 except ImportError:
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
10 sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
11 import test_util
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
12
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
13 # interesting and fast tests
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
14 import test_fetch_mappings
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
15 import test_fetch_renames
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
16 import test_pull
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
17 import test_template_keywords
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
18 import test_utility_commands
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
19
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
20 # comprehensive tests
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
21 try:
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
22 import test_custom_layout
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
23 except ImportError:
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
24 sys.path.insert(0, os.path.dirname(__file__))
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
25 import test_custom_layout
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
26
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
27 import test_rebuildmeta
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
28 import test_updatemeta
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
29
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
30 from hgsubversion import svnmeta, maps
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
31
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
32
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
33 class SqliteRevMapMixIn(object):
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
34 # do not double the test size by being wrapped again
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
35 obsolete_mode_tests = False
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
36 stupid_mode_tests = False
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
37
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
38 def setUp(self):
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
39 assert svnmeta.SVNMeta._defaultrevmapclass is maps.RevMap
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
40 svnmeta.SVNMeta._defaultrevmapclass = maps.SqliteRevMap
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
41 super(SqliteRevMapMixIn, self).setUp()
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
42
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
43 def tearDown(self):
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
44 assert svnmeta.SVNMeta._defaultrevmapclass is maps.SqliteRevMap
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
45 svnmeta.SVNMeta._defaultrevmapclass = maps.RevMap
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
46 super(SqliteRevMapMixIn, self).tearDown()
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
47
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
48 def shortDescription(self):
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
49 text = super(SqliteRevMapMixIn, self).shortDescription()
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
50 if text:
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
51 text += ' (sqlite revmap)'
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
52 return text
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
53
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
54 def buildtestclass(cls, selector=None):
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
55 name = 'SqliteRevMap%s' % cls.__name__
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
56 newcls = type(name, (SqliteRevMapMixIn, cls,), {})
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
57
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
58 # remove test cases not selected by selector
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
59 if selector:
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
60 for name in dir(newcls):
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
61 if name.startswith('test_') and not selector(name[5:]):
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
62 setattr(newcls, name, None)
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
63
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
64 globals()[name] = newcls
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
65
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
66 def svndumpselector(name):
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
67 return name in ['branch_rename_to_trunk',
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
68 'tag_name_same_as_branch']
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
69
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
70 buildtestclass(test_fetch_mappings.MapTests)
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
71 buildtestclass(test_fetch_renames.TestFetchRenames)
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
72 buildtestclass(test_pull.TestPull)
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
73 buildtestclass(test_template_keywords.TestLogKeywords)
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
74 buildtestclass(test_utility_commands.UtilityTests)
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
75
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
76 buildtestclass(test_rebuildmeta.RebuildMetaTests, svndumpselector)
f21605bcda24 tests: add the sqlite revmap test
Jun Wu <quark@fb.com>
parents:
diff changeset
77 buildtestclass(test_updatemeta.UpdateMetaTests, svndumpselector)