Mercurial > hg
annotate tests/test-storage.py @ 40323:2c0aa02ecd5a
testing: switch to inserting deltas
As the comment in the test specifies, this was relying on storage backend
implementation details. We switch to inserting a raw delta, skipping the
regular insert path to ensure we have the desired outcome. This required
implementing support for handling deltas in the revlog testing code.
Differential Revision: https://phab.mercurial-scm.org/D5116
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Tue, 16 Oct 2018 16:24:46 +0200 |
parents | 9b2e1b00ee94 |
children | fed697fa1734 |
rev | line source |
---|---|
39772
ae531f5e583c
testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1 # This test verifies the conformance of various classes to various |
ae531f5e583c
testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2 # storage interfaces. |
ae531f5e583c
testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3 from __future__ import absolute_import |
ae531f5e583c
testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
4 |
ae531f5e583c
testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
5 import silenttestrunner |
ae531f5e583c
testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
6 |
ae531f5e583c
testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
7 from mercurial import ( |
40051
cdf61ab1f54c
testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39953
diff
changeset
|
8 error, |
39772
ae531f5e583c
testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
9 filelog, |
40051
cdf61ab1f54c
testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39953
diff
changeset
|
10 revlog, |
39772
ae531f5e583c
testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
11 transaction, |
ae531f5e583c
testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
12 ui as uimod, |
ae531f5e583c
testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
13 vfs as vfsmod, |
ae531f5e583c
testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
14 ) |
ae531f5e583c
testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
15 |
ae531f5e583c
testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
16 from mercurial.testing import ( |
ae531f5e583c
testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
17 storage as storagetesting, |
ae531f5e583c
testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
18 ) |
ae531f5e583c
testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
19 |
ae531f5e583c
testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
20 STATE = { |
ae531f5e583c
testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
21 'lastindex': 0, |
ae531f5e583c
testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
22 'ui': uimod.ui(), |
ae531f5e583c
testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
23 'vfs': vfsmod.vfs(b'.', realpath=True), |
ae531f5e583c
testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
24 } |
ae531f5e583c
testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
25 |
ae531f5e583c
testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
26 def makefilefn(self): |
ae531f5e583c
testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
27 """Factory for filelog instances.""" |
39953
a3a9b93bff80
py3: byteify test-storage.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39772
diff
changeset
|
28 fl = filelog.filelog(STATE['vfs'], b'filelog-%d' % STATE['lastindex']) |
39772
ae531f5e583c
testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
29 STATE['lastindex'] += 1 |
ae531f5e583c
testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
30 return fl |
ae531f5e583c
testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
31 |
ae531f5e583c
testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
32 def maketransaction(self): |
40320
9b2e1b00ee94
tests: use byte literals in test-storage.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40056
diff
changeset
|
33 vfsmap = {b'plain': STATE['vfs'], b'store': STATE['vfs']} |
39772
ae531f5e583c
testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
34 |
ae531f5e583c
testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
35 return transaction.transaction(STATE['ui'].warn, STATE['vfs'], vfsmap, |
39953
a3a9b93bff80
py3: byteify test-storage.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39772
diff
changeset
|
36 b'journal', b'undo') |
39772
ae531f5e583c
testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
37 |
40051
cdf61ab1f54c
testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39953
diff
changeset
|
38 def addrawrevision(self, fl, tr, node, p1, p2, linkrev, rawtext=None, |
cdf61ab1f54c
testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39953
diff
changeset
|
39 delta=None, censored=False, ellipsis=False, extstored=False): |
cdf61ab1f54c
testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39953
diff
changeset
|
40 flags = 0 |
cdf61ab1f54c
testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39953
diff
changeset
|
41 |
cdf61ab1f54c
testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39953
diff
changeset
|
42 if censored: |
cdf61ab1f54c
testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39953
diff
changeset
|
43 flags |= revlog.REVIDX_ISCENSORED |
cdf61ab1f54c
testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39953
diff
changeset
|
44 if ellipsis: |
cdf61ab1f54c
testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39953
diff
changeset
|
45 flags |= revlog.REVIDX_ELLIPSIS |
cdf61ab1f54c
testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39953
diff
changeset
|
46 if extstored: |
cdf61ab1f54c
testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39953
diff
changeset
|
47 flags |= revlog.REVIDX_EXTSTORED |
cdf61ab1f54c
testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39953
diff
changeset
|
48 |
cdf61ab1f54c
testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39953
diff
changeset
|
49 if rawtext is not None: |
cdf61ab1f54c
testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39953
diff
changeset
|
50 fl._revlog.addrawrevision(rawtext, tr, linkrev, p1, p2, node, flags) |
cdf61ab1f54c
testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39953
diff
changeset
|
51 elif delta is not None: |
40323
2c0aa02ecd5a
testing: switch to inserting deltas
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40320
diff
changeset
|
52 fl._revlog.addrawrevision(rawtext, tr, linkrev, p1, p2, node, flags, |
2c0aa02ecd5a
testing: switch to inserting deltas
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40320
diff
changeset
|
53 cachedelta=delta) |
40051
cdf61ab1f54c
testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39953
diff
changeset
|
54 else: |
cdf61ab1f54c
testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39953
diff
changeset
|
55 raise error.Abort('must supply rawtext or delta arguments') |
cdf61ab1f54c
testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39953
diff
changeset
|
56 |
cdf61ab1f54c
testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39953
diff
changeset
|
57 # We may insert bad data. Clear caches to prevent e.g. cache hits to |
cdf61ab1f54c
testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39953
diff
changeset
|
58 # bypass hash verification. |
cdf61ab1f54c
testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39953
diff
changeset
|
59 fl._revlog.clearcaches() |
cdf61ab1f54c
testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39953
diff
changeset
|
60 |
39772
ae531f5e583c
testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
61 # Assigning module-level attributes that inherit from unittest.TestCase |
ae531f5e583c
testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
62 # is all that is needed to register tests. |
ae531f5e583c
testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
63 filelogindextests = storagetesting.makeifileindextests(makefilefn, |
40051
cdf61ab1f54c
testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39953
diff
changeset
|
64 maketransaction, |
cdf61ab1f54c
testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39953
diff
changeset
|
65 addrawrevision) |
39772
ae531f5e583c
testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
66 filelogdatatests = storagetesting.makeifiledatatests(makefilefn, |
40051
cdf61ab1f54c
testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39953
diff
changeset
|
67 maketransaction, |
cdf61ab1f54c
testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39953
diff
changeset
|
68 addrawrevision) |
39772
ae531f5e583c
testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
69 filelogmutationtests = storagetesting.makeifilemutationtests(makefilefn, |
40051
cdf61ab1f54c
testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39953
diff
changeset
|
70 maketransaction, |
cdf61ab1f54c
testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39953
diff
changeset
|
71 addrawrevision) |
39772
ae531f5e583c
testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
72 |
ae531f5e583c
testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
73 if __name__ == '__main__': |
ae531f5e583c
testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
74 silenttestrunner.main(__name__) |