Patchwork [03,of,10,V2] revlog: add some direct testing of the slicing logic

login
register
mail settings
Submitter Boris Feld
Date Dec. 21, 2018, 11:47 a.m.
Message ID <6236b26993a268a3bbf3.1545392826@localhost.localdomain>
Download mbox | patch
Permalink /patch/37295/
State Accepted
Headers show

Comments

Boris Feld - Dec. 21, 2018, 11:47 a.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1545304635 -3600
#      Thu Dec 20 12:17:15 2018 +0100
# Node ID 6236b26993a268a3bbf3269e44159aa979d2e625
# Parent  df9b79e863d6e5215175487330b1469067e20bbd
# EXP-Topic sparse-revlog
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 6236b26993a2
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).
Yuya Nishihara - Dec. 22, 2018, 3:41 a.m.
On Fri, 21 Dec 2018 12:47:06 +0100, Boris Feld wrote:
> # HG changeset patch
> # User Boris Feld <boris.feld@octobus.net>
> # Date 1545304635 -3600
> #      Thu Dec 20 12:17:15 2018 +0100
> # Node ID 6236b26993a268a3bbf3269e44159aa979d2e625
> # Parent  df9b79e863d6e5215175487330b1469067e20bbd
> # EXP-Topic sparse-revlog
> # Available At https://bitbucket.org/octobus/mercurial-devel/
> #              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 6236b26993a2
> revlog: add some direct testing of the slicing logic

Queued 3 and 4 as well, thanks. I fixed several Python 3 issues.

Patch

diff --git a/tests/test-revlog-raw.py b/tests/test-revlog-raw.py
--- a/tests/test-revlog-raw.py
+++ b/tests/test-revlog-raw.py
@@ -12,11 +12,15 @@  from mercurial import (
     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, 'sparse-revlog': True}
 
 # The test wants to control whether to use delta explicitly, based on
 # "storedeltachains".
@@ -291,6 +295,38 @@  def checkrevlog(rlog, expected):
                             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 @@  def maintest():
         rl4 = lowlevelcopy(rl, tr)
         checkrevlog(rl4, expected)
         print('lowlevelcopy test passed')
+        slicingtest(rl)
+        print('slicing test passed')
 
 try:
     maintest()
diff --git a/tests/test-revlog-raw.py.out b/tests/test-revlog-raw.py.out
--- a/tests/test-revlog-raw.py.out
+++ b/tests/test-revlog-raw.py.out
@@ -2,3 +2,4 @@  local test passed
 addgroupcopy test passed
 clone test passed
 lowlevelcopy test passed
+slicing test passed