Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Unified Diff: client/tests/isolateserver_test.py

Issue 2414543003: isolateserver: DiskCache format v2 (Closed)
Patch Set: typo and nit Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: client/tests/isolateserver_test.py
diff --git a/client/tests/isolateserver_test.py b/client/tests/isolateserver_test.py
index 550e16108a942bbb6f5a94760fae5b7ed08a3003..4644273e4972f09c0770ea08d7eee197e7979c3c 100755
--- a/client/tests/isolateserver_test.py
+++ b/client/tests/isolateserver_test.py
@@ -1248,8 +1248,11 @@ class DiskCacheTest(TestCase):
# TODO(maruel): Test the following.
#cache.touch()
+ self.now = 0.0
+
def get_cache(self):
- return isolateserver.DiskCache(self.tempdir, self._policies, self._algo)
+ return isolateserver.DiskCache(
+ self.tempdir, self._policies, self._algo, time_fn=lambda: self.now)
def to_hash(self, content):
return self._algo(content).hexdigest(), content
@@ -1291,11 +1294,10 @@ class DiskCacheTest(TestCase):
h_a = self.to_hash('a')[0]
isolateserver.file_write(os.path.join(self.tempdir, h_a), 'a')
cache = self.get_cache()
- self.assertEqual([], sorted(cache._lru._items.iteritems()))
- self.assertEqual(
- sorted([h_a, u'state.json']), sorted(os.listdir(self.tempdir)))
+ self.assertEqual([], sorted(cache._lru.iteritems()))
+ self.assertEqual(sorted([h_a]), sorted(os.listdir(self.tempdir)))
cache.cleanup()
- self.assertEqual([u'state.json'], os.listdir(self.tempdir))
+ self.assertEqual([], os.listdir(self.tempdir))
def test_policies_active_trimming(self):
# Start with a larger cache, add many object.
@@ -1316,7 +1318,7 @@ class DiskCacheTest(TestCase):
# cache policies. As long as there is free space, this is fine.
cache.write(h_b, 'b')
expected = sorted(((h_a, 1), (h_large, len(large)), (h_b, 1)))
- self.assertEqual(expected, sorted(cache._lru._items.iteritems()))
+ self.assertEqual(expected, sorted(cache._sizes()))
self.assertEqual(h_a, cache._protected)
self.assertEqual(1000, cache._free_disk)
self.assertEqual(0, cache.initial_number_items)
@@ -1330,7 +1332,8 @@ class DiskCacheTest(TestCase):
# At this point, after the implicit trim in __exit__(), h_a and h_large were
# evicted.
self.assertEqual(
- sorted([h_b, h_c, u'state.json']), sorted(os.listdir(self.tempdir)))
+ set([h_b[:2], h_c[:2], u'state.json']),
+ set(os.listdir(self.tempdir)))
# Allow 3 items and 101 bytes so h_large is kept.
self._policies = isolateserver.CachePolicies(101, 1000, 3)
@@ -1340,19 +1343,41 @@ class DiskCacheTest(TestCase):
self.assertEqual(2, cache.initial_size)
self.assertEqual(
- sorted([h_b, h_c, h_large, u'state.json']),
- sorted(os.listdir(self.tempdir)))
+ set([h_b[:2], h_c[:2], h_large[:2], u'state.json']),
+ set(os.listdir(self.tempdir)))
# Assert that trimming is done in constructor too.
self._policies = isolateserver.CachePolicies(100, 1000, 2)
with self.get_cache() as cache:
- expected = collections.OrderedDict([(h_c, 1), (h_large, len(large))])
- self.assertEqual(expected, cache._lru._items)
+ self.assertEqual(
+ [(h_c, 1), (h_large, len(large))],
+ list(cache._sizes()))
self.assertEqual(None, cache._protected)
self.assertEqual(1101, cache._free_disk)
self.assertEqual(2, cache.initial_number_items)
self.assertEqual(100, cache.initial_size)
+ def test_timestamp(self):
+ self._free_disk = 1100
+ cache = self.get_cache()
+ with cache:
+ self.now = 1
+ cache.write('deadbeef', '1')
+
+ self.now = 2
+ cache.write('badcoffee', '2')
+
+ self.assertEqual(
+ [
+ ('deadbeef', [1, 1]),
+ ('badcoffee', [1, 2]),
+ ],
+ cache._lru.items()
+ )
+
+ loaded = self.get_cache()
+ self.assertEqual(cache._lru, loaded._lru)
+
def clear_env_vars():
for e in ('ISOLATE_DEBUG', 'ISOLATE_SERVER'):
« client/isolateserver.py ('K') | « client/isolateserver.py ('k') | client/tests/lru_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698