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

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

Issue 2866283002: named caches: move instead of symlinking (Closed)
Patch Set: final comments Created 3 years, 7 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/tests/named_cache_test.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=R0201 6 # pylint: disable=R0201
7 7
8 import StringIO 8 import StringIO
9 import base64 9 import base64
10 import contextlib 10 import contextlib
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 with open(p, 'rb') as f: 64 with open(p, 'rb') as f:
65 out[os.path.relpath(p, path)] = f.read() 65 out[os.path.relpath(p, path)] = f.read()
66 return out 66 return out
67 67
68 68
69 @contextlib.contextmanager 69 @contextlib.contextmanager
70 def init_named_caches_stub(_run_dir): 70 def init_named_caches_stub(_run_dir):
71 yield 71 yield
72 72
73 73
74 def put_to_named_cache(manager, cache_name, file_name, contents):
75 """Puts files into named cache."""
76 tdir = tempfile.mkdtemp(prefix=u'run_isolated_test')
77 try:
78 cache_dir = os.path.join(tdir, 'cache')
79 manager.install(cache_dir, cache_name)
80 with open(os.path.join(cache_dir, file_name), 'wb') as f:
81 f.write(contents)
82 manager.uninstall(cache_dir, cache_name)
83 finally:
84 file_path.rmtree(tdir)
85
86
74 class StorageFake(object): 87 class StorageFake(object):
75 def __init__(self, files): 88 def __init__(self, files):
76 self._files = files.copy() 89 self._files = files.copy()
77 self.namespace = 'default-gzip' 90 self.namespace = 'default-gzip'
78 self.location = 'http://localhost:1' 91 self.location = 'http://localhost:1'
79 92
80 def __enter__(self, *_): 93 def __enter__(self, *_):
81 return self 94 return self
82 95
83 def __exit__(self, *_): 96 def __exit__(self, *_):
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 '--named-cache-root', os.path.join(self.tempdir, 'c'), 539 '--named-cache-root', os.path.join(self.tempdir, 'c'),
527 '--named-cache', 'cache_foo', 'foo', 540 '--named-cache', 'cache_foo', 'foo',
528 '--named-cache', 'cache_bar', 'bar', 541 '--named-cache', 'cache_bar', 'bar',
529 'bin/echo${EXECUTABLE_SUFFIX}', 542 'bin/echo${EXECUTABLE_SUFFIX}',
530 'hello', 543 'hello',
531 'world', 544 'world',
532 ] 545 ]
533 ret = run_isolated.main(cmd) 546 ret = run_isolated.main(cmd)
534 self.assertEqual(0, ret) 547 self.assertEqual(0, ret)
535 548
536 for path, cache_name in [('foo', 'cache_foo'), ('bar', 'cache_bar')]: 549 for cache_name in ('cache_foo', 'cache_bar'):
550 named_path = os.path.join(self.tempdir, 'c', 'named', cache_name)
551 self.assertTrue(os.path.exists(named_path))
537 self.assertEqual( 552 self.assertEqual(
538 os.path.abspath(os.readlink( 553 os.path.join(self.tempdir, 'c'),
539 os.path.join(self.tempdir, 'ir', path))), 554 os.path.dirname(os.readlink(named_path)),
540 os.path.abspath(os.readlink(
541 os.path.join(self.tempdir, 'c', 'named', cache_name))),
542 ) 555 )
543 556
544 def test_modified_cwd(self): 557 def test_modified_cwd(self):
545 isolated = json_dumps({ 558 isolated = json_dumps({
546 'command': ['../out/some.exe', 'arg'], 559 'command': ['../out/some.exe', 'arg'],
547 'relative_cwd': 'some', 560 'relative_cwd': 'some',
548 }) 561 })
549 isolated_hash = isolateserver_mock.hash_content(isolated) 562 isolated_hash = isolateserver_mock.hash_content(isolated)
550 files = {isolated_hash:isolated} 563 files = {isolated_hash:isolated}
551 _ = self._run_tha_test(isolated_hash, files) 564 _ = self._run_tha_test(isolated_hash, files)
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 big = small * 1014 615 big = small * 1014
603 small_digest = unicode(ALGO(small).hexdigest()) 616 small_digest = unicode(ALGO(small).hexdigest())
604 big_digest = unicode(ALGO(big).hexdigest()) 617 big_digest = unicode(ALGO(big).hexdigest())
605 with isolate_cache: 618 with isolate_cache:
606 fake_time = 1 619 fake_time = 1
607 isolate_cache.write(big_digest, [big]) 620 isolate_cache.write(big_digest, [big])
608 fake_time = 2 621 fake_time = 2
609 isolate_cache.write(small_digest, [small]) 622 isolate_cache.write(small_digest, [small])
610 with named_cache_manager.open(time_fn=lambda: fake_time): 623 with named_cache_manager.open(time_fn=lambda: fake_time):
611 fake_time = 1 624 fake_time = 1
612 p = named_cache_manager.request('first') 625 put_to_named_cache(named_cache_manager, u'first', u'big', big)
613 with open(os.path.join(p, 'big'), 'wb') as f:
614 f.write(big)
615 fake_time = 3 626 fake_time = 3
616 p = named_cache_manager.request('second') 627 put_to_named_cache(named_cache_manager, u'second', u'small', small)
617 with open(os.path.join(p, 'small'), 'wb') as f:
618 f.write(small)
619 628
620 # Ensures the cache contain the expected data. 629 # Ensures the cache contain the expected data.
621 actual = genTree(np) 630 actual = genTree(np)
622 # Figure out the cache path names. 631 # Figure out the cache path names.
623 cache_small = [ 632 cache_small = [
624 os.path.dirname(n) for n in actual if os.path.basename(n) == 'small'][0] 633 os.path.dirname(n) for n in actual if os.path.basename(n) == 'small'][0]
625 cache_big = [ 634 cache_big = [
626 os.path.dirname(n) for n in actual if os.path.basename(n) == 'big'][0] 635 os.path.dirname(n) for n in actual if os.path.basename(n) == 'big'][0]
627 expected = { 636 expected = {
628 os.path.join(cache_small, u'small'): small, 637 os.path.join(cache_small, u'small'): small,
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
985 self.assertEqual(expected, actual) 994 self.assertEqual(expected, actual)
986 995
987 996
988 if __name__ == '__main__': 997 if __name__ == '__main__':
989 fix_encoding.fix_encoding() 998 fix_encoding.fix_encoding()
990 if '-v' in sys.argv: 999 if '-v' in sys.argv:
991 unittest.TestCase.maxDiff = None 1000 unittest.TestCase.maxDiff = None
992 logging.basicConfig( 1001 logging.basicConfig(
993 level=logging.DEBUG if '-v' in sys.argv else logging.ERROR) 1002 level=logging.DEBUG if '-v' in sys.argv else logging.ERROR)
994 unittest.main() 1003 unittest.main()
OLDNEW
« no previous file with comments | « client/tests/named_cache_test.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698