comparison tests/test-storage.py @ 40051:cdf61ab1f54c

testing: add file storage integration for bad hashes and censoring In order to implement these tests, we need a backdoor to write data into storage backends while bypassing normal checks. We invent a callable to do that. As part of writing the tests, I found a bug with censorrevision() pretty quickly! After calling censorrevision(), attempting to access revision data for an affected node raises a cryptic error related to malformed compression. This appears to be due to the revlog not adjusting delta chains as part of censoring. I also found a bug with regards to hash verification and revision fulltext caching. Essentially, we cache the fulltext before hash verification. If we look up the fulltext after a failed hash verification, we don't get a hash verification exception. Furthermore, the behavior of revision(raw=True) can be inconsistent depending on the order of operations. I'll be fixing both these bugs in subsequent commits. Differential Revision: https://phab.mercurial-scm.org/D4865
author Gregory Szorc <gregory.szorc@gmail.com>
date Wed, 03 Oct 2018 10:56:48 -0700
parents a3a9b93bff80
children 324b4b10351e
comparison
equal deleted inserted replaced
40050:8e136940c0e6 40051:cdf61ab1f54c
3 from __future__ import absolute_import 3 from __future__ import absolute_import
4 4
5 import silenttestrunner 5 import silenttestrunner
6 6
7 from mercurial import ( 7 from mercurial import (
8 error,
8 filelog, 9 filelog,
10 revlog,
9 transaction, 11 transaction,
10 ui as uimod, 12 ui as uimod,
11 vfs as vfsmod, 13 vfs as vfsmod,
12 ) 14 )
13 15
31 vfsmap = {'plain': STATE['vfs']} 33 vfsmap = {'plain': STATE['vfs']}
32 34
33 return transaction.transaction(STATE['ui'].warn, STATE['vfs'], vfsmap, 35 return transaction.transaction(STATE['ui'].warn, STATE['vfs'], vfsmap,
34 b'journal', b'undo') 36 b'journal', b'undo')
35 37
38 def addrawrevision(self, fl, tr, node, p1, p2, linkrev, rawtext=None,
39 delta=None, censored=False, ellipsis=False, extstored=False):
40 flags = 0
41
42 if censored:
43 flags |= revlog.REVIDX_ISCENSORED
44 if ellipsis:
45 flags |= revlog.REVIDX_ELLIPSIS
46 if extstored:
47 flags |= revlog.REVIDX_EXTSTORED
48
49 if rawtext is not None:
50 fl._revlog.addrawrevision(rawtext, tr, linkrev, p1, p2, node, flags)
51 elif delta is not None:
52 raise error.Abort('support for storing raw deltas not yet supported')
53 else:
54 raise error.Abort('must supply rawtext or delta arguments')
55
56 # We may insert bad data. Clear caches to prevent e.g. cache hits to
57 # bypass hash verification.
58 fl._revlog.clearcaches()
59
36 # Assigning module-level attributes that inherit from unittest.TestCase 60 # Assigning module-level attributes that inherit from unittest.TestCase
37 # is all that is needed to register tests. 61 # is all that is needed to register tests.
38 filelogindextests = storagetesting.makeifileindextests(makefilefn, 62 filelogindextests = storagetesting.makeifileindextests(makefilefn,
39 maketransaction) 63 maketransaction,
64 addrawrevision)
40 filelogdatatests = storagetesting.makeifiledatatests(makefilefn, 65 filelogdatatests = storagetesting.makeifiledatatests(makefilefn,
41 maketransaction) 66 maketransaction,
67 addrawrevision)
42 filelogmutationtests = storagetesting.makeifilemutationtests(makefilefn, 68 filelogmutationtests = storagetesting.makeifilemutationtests(makefilefn,
43 maketransaction) 69 maketransaction,
70 addrawrevision)
44 71
45 if __name__ == '__main__': 72 if __name__ == '__main__':
46 silenttestrunner.main(__name__) 73 silenttestrunner.main(__name__)