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

Side by Side Diff: client/tests/isolateserver_test.py

Issue 2610273002: Make isolate cache resilient to unexpectedly deleted items. (Closed)
Patch Set: Created 3 years, 11 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 unified diff | Download patch
« no previous file with comments | « client/isolateserver.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2013 The LUCI Authors. All rights reserved. 2 # Copyright 2013 The LUCI Authors. All rights reserved.
3 # Use of this source code is governed under the Apache License, Version 2.0 3 # Use of this source code is governed under the Apache License, Version 2.0
4 # that can be found in the LICENSE file. 4 # that can be found in the LICENSE file.
5 5
6 # pylint: disable=W0212,W0223,W0231,W0613 6 # pylint: disable=W0212,W0223,W0231,W0613
7 7
8 import base64 8 import base64
9 import collections
10 import hashlib 9 import hashlib
11 import json 10 import json
12 import logging 11 import logging
13 import io 12 import io
14 import os 13 import os
15 import StringIO 14 import StringIO
16 import sys 15 import sys
17 import tarfile 16 import tarfile
18 import tempfile 17 import tempfile
19 import unittest 18 import unittest
20 import urllib
21 import zlib 19 import zlib
22 20
23 # net_utils adjusts sys.path. 21 # net_utils adjusts sys.path.
24 import net_utils 22 import net_utils
25 23
26 import auth 24 import auth
27 import isolated_format 25 import isolated_format
28 import isolateserver 26 import isolateserver
29 import isolate_storage 27 import isolate_storage
30 import test_utils 28 import test_utils
31 from depot_tools import auto_stub
32 from depot_tools import fix_encoding 29 from depot_tools import fix_encoding
33 from utils import file_path 30 from utils import file_path
34 from utils import fs 31 from utils import fs
35 from utils import logging_utils 32 from utils import logging_utils
36 from utils import threading_utils 33 from utils import threading_utils
37 34
38 import isolateserver_mock 35 import isolateserver_mock
39 36
40 37
41 CONTENTS = { 38 CONTENTS = {
(...skipping 1397 matching lines...) Expand 10 before | Expand all | Expand 10 after
1439 1436
1440 # Assert that trimming is done in constructor too. 1437 # Assert that trimming is done in constructor too.
1441 self._policies = isolateserver.CachePolicies(100, 1000, 2) 1438 self._policies = isolateserver.CachePolicies(100, 1000, 2)
1442 with self.get_cache() as cache: 1439 with self.get_cache() as cache:
1443 assertItems([(h_c, 1), (h_large, len(large))]) 1440 assertItems([(h_c, 1), (h_large, len(large))])
1444 self.assertEqual(None, cache._protected) 1441 self.assertEqual(None, cache._protected)
1445 self.assertEqual(1101, cache._free_disk) 1442 self.assertEqual(1101, cache._free_disk)
1446 self.assertEqual(2, cache.initial_number_items) 1443 self.assertEqual(2, cache.initial_number_items)
1447 self.assertEqual(100, cache.initial_size) 1444 self.assertEqual(100, cache.initial_size)
1448 1445
1446 def test_some_file_brutally_deleted(self):
1447 h_a = self.to_hash('a')[0]
1448
1449 self._free_disk = 1100
1450 with self.get_cache() as cache:
1451 cache.write(h_a, 'a')
1452 self.assertTrue(cache.touch(h_a, isolateserver.UNKNOWN_FILE_SIZE))
1453 self.assertTrue(cache.touch(h_a, 1))
1454
1455 os.remove(os.path.join(self.tempdir, h_a))
1456
1457 with self.get_cache() as cache:
1458 # 'Ghost' entry loaded with state.json is still there.
1459 self.assertEqual({h_a}, cache.cached_set())
1460 # 'touch' detects the file is missing by returning False.
1461 self.assertFalse(cache.touch(h_a, isolateserver.UNKNOWN_FILE_SIZE))
1462 self.assertFalse(cache.touch(h_a, 1))
1463 # Evicting it still works, kills the 'ghost' entry.
1464 cache.evict(h_a)
1465 self.assertEqual(set(), cache.cached_set())
1466
1449 1467
1450 def clear_env_vars(): 1468 def clear_env_vars():
1451 for e in ('ISOLATE_DEBUG', 'ISOLATE_SERVER'): 1469 for e in ('ISOLATE_DEBUG', 'ISOLATE_SERVER'):
1452 os.environ.pop(e, None) 1470 os.environ.pop(e, None)
1453 1471
1454 1472
1455 if __name__ == '__main__': 1473 if __name__ == '__main__':
1456 fix_encoding.fix_encoding() 1474 fix_encoding.fix_encoding()
1457 if '-v' in sys.argv: 1475 if '-v' in sys.argv:
1458 unittest.TestCase.maxDiff = None 1476 unittest.TestCase.maxDiff = None
1459 logging.basicConfig( 1477 logging.basicConfig(
1460 level=(logging.DEBUG if '-v' in sys.argv else logging.CRITICAL)) 1478 level=(logging.DEBUG if '-v' in sys.argv else logging.CRITICAL))
1461 clear_env_vars() 1479 clear_env_vars()
1462 unittest.main() 1480 unittest.main()
OLDNEW
« no previous file with comments | « client/isolateserver.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698