Mercurial > hg-stable
changeset 41037:cca12a31ede5
revlog: add some direct testing of the slicing logic
This test check slicing backed by an actual revlog. It will test the C version
of slicing (if the test are run with the C extensions).
author | Boris Feld <boris.feld@octobus.net> |
---|---|
date | Thu, 20 Dec 2018 12:17:15 +0100 |
parents | b373477948df |
children | 15f78383d3c8 |
files | tests/test-revlog-raw.py tests/test-revlog-raw.py.out |
diffstat | 2 files changed, 40 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/tests/test-revlog-raw.py Wed Dec 19 10:54:25 2018 +0100 +++ b/tests/test-revlog-raw.py Thu Dec 20 12:17:15 2018 +0100 @@ -12,11 +12,16 @@ vfs, ) +from mercurial.revlogutils import ( + deltas, +) + # TESTTMP is optional. This makes it convenient to run without run-tests.py tvfs = vfs.vfs(encoding.environ.get(b'TESTTMP', b'/tmp')) # Enable generaldelta otherwise revlog won't use delta as expected by the test -tvfs.options = {b'generaldelta': True, b'revlogv1': True} +tvfs.options = {b'generaldelta': True, b'revlogv1': True, + b'sparse-revlog': True} # The test wants to control whether to use delta explicitly, based on # "storedeltachains". @@ -291,6 +296,37 @@ abort('rev %d: corrupted %stext' % (rev, raw and 'raw' or '')) +slicingdata = [ + ([0, 1, 2, 3, 55, 56, 58, 59, 60], + [[0, 1], [2], [58], [59, 60]], + 10), + ([0, 1, 2, 3, 55, 56, 58, 59, 60], + [[0, 1], [2], [58], [59, 60]], + 10), + ([-1, 0, 1, 2, 3, 55, 56, 58, 59, 60], + [[-1, 0, 1], [2], [58], [59, 60]], + 10), +] + +def slicingtest(rlog): + oldmin = rlog._srmingapsize + try: + # the test revlog is small, we remove the floor under which we + # slicing is diregarded. + rlog._srmingapsize = 0 + for item in slicingdata: + chain, expected, target = item + result = deltas.slicechunk(rlog, chain, targetsize=target) + result = list(result) + if result != expected: + print('slicing differ:') + print(' chain: %s' % chain) + print(' target: %s' % target) + print(' expected: %s' % expected) + print(' result: %s' % result) + finally: + rlog._srmingapsize = oldmin + def maintest(): expected = rl = None with newtransaction() as tr: @@ -313,6 +349,8 @@ rl4 = lowlevelcopy(rl, tr) checkrevlog(rl4, expected) print('lowlevelcopy test passed') + slicingtest(rl) + print('slicing test passed') try: maintest()