diff --git a/py/misc/cache.py b/py/misc/cache.py index 51e345d52..12970e6d7 100644 --- a/py/misc/cache.py +++ b/py/misc/cache.py @@ -107,9 +107,6 @@ class BuildcostAccessCache(BasicCache): # time function to use for measuring build-times _time = gettime - def __init__(self, maxentries=64): - super(BuildcostAccessCache, self).__init__(maxentries) - def build(self, key, builder, *args, **kwargs): start = self._time() val = builder(*args, **kwargs) diff --git a/py/misc/testing/test_cache.py b/py/misc/testing/test_cache.py index c4c8f5df2..be4e3406b 100644 --- a/py/misc/testing/test_cache.py +++ b/py/misc/testing/test_cache.py @@ -27,6 +27,12 @@ class TestBuildcostAccess(BasicCacheAPITest): def test_cache_works_somewhat_simple(self): cache = BuildcostAccessCache() + # the default ._time() call used by + # BuildcostAccessCache.build can + # result into time()-time() == 0 which makes the below + # test fail randomly. Let's rather use incrementing + # numbers instead. + cache._time = py.std.itertools.count().next for x in range(cache.maxentries): y = cache.getorbuild(x, lambda: x) assert x == y