sapling/tests/test-fastmanifest.py
Laurent Charignon 49185d4bb2 fastmanifest: shuffle by batches
Summary:
As discussed in the group, we want to shuffle by batches to keep
an approximate ordering and still avoid caching process fighting for the
same entries.

Test Plan: Add a new test

Reviewers: durham, ttung

Differential Revision: https://phabricator.intern.facebook.com/D3344144
2016-05-26 09:52:55 -07:00

47 lines
1.6 KiB
Python

import silenttestrunner
import unittest
import os
import sys
from mercurial import manifest
from mercurial import scmutil
from mercurial import util
class HybridManifest(unittest.TestCase):
def test_wrap(self):
"""If a new magic method is added to manifestdict, we want to make sure
that hybridmanifest implement it, this test validates that all magic
methods of manifestdict are implemented by hybridmanifest to avoid
breakage in prod
"""
vfs = scmutil.vfs('')
hd = fastmanifest.hybridmanifest(None, vfs)
ismagic = lambda x: x.startswith("__") and x.endswith("__")
magicmethods = [k
for k, v in manifest.manifestdict.__dict__.items()
if util.safehasattr(v, '__call__') and ismagic(k)]
for method in magicmethods:
assert util.safehasattr(hd, method),\
"%s missing in hybrid manifest" % method
def test_cachelimit(self):
cachealloc = fastmanifest.systemawarecachelimit.cacheallocation
GB = fastmanifest.GB
MB = fastmanifest.MB
assert cachealloc(0) == 0
assert cachealloc(120 * GB) == 6 * GB
assert abs(cachealloc(28 * GB) - 5.6 * GB) < 5 * MB
def test_shufflebybatch(self):
data = range(10000)
fastmanifest.shufflebybatch(data, 5)
assert len(data) == 10000
assert data != range(10000)
if __name__ == "__main__":
sys.path.insert(0, os.path.join(os.environ["TESTDIR"], ".."))
import fastmanifest
silenttestrunner.main(__name__)