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

Side by Side Diff: appengine/swarming/swarming_bot/bot_code/task_runner_test.py

Issue 2877483004: Reland "named caches: move instead of symlinking" (Closed)
Patch Set: address 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 | « appengine/swarming/local_smoke_test.py ('k') | client/named_cache.py » ('j') | 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 # coding=utf-8 2 # coding=utf-8
3 # Copyright 2013 The LUCI Authors. All rights reserved. 3 # Copyright 2013 The LUCI Authors. All rights reserved.
4 # Use of this source code is governed under the Apache License, Version 2.0 4 # Use of this source code is governed under the Apache License, Version 2.0
5 # that can be found in the LICENSE file. 5 # that can be found in the LICENSE file.
6 6
7 import base64 7 import base64
8 import contextlib
8 import json 9 import json
9 import logging 10 import logging
10 import os 11 import os
11 import re 12 import re
12 import signal 13 import signal
13 import sys 14 import sys
14 import tempfile 15 import tempfile
15 import time 16 import time
16 import unittest 17 import unittest
17 18
18 import test_env_bot_code 19 import test_env_bot_code
19 test_env_bot_code.setup_test_env() 20 test_env_bot_code.setup_test_env()
20 21
21 # Creates a server mock for functions in net.py. 22 # Creates a server mock for functions in net.py.
22 import net_utils 23 import net_utils
23 24
24 from depot_tools import fix_encoding 25 from depot_tools import fix_encoding
25 from utils import file_path 26 from utils import file_path
26 from utils import large 27 from utils import large
27 from utils import logging_utils 28 from utils import logging_utils
28 from utils import subprocess42 29 from utils import subprocess42
29 from libs import luci_context 30 from libs import luci_context
30 import bot_auth 31 import bot_auth
32 import fake_swarming
33 import named_cache
31 import remote_client 34 import remote_client
32 import fake_swarming
33 import task_runner 35 import task_runner
34 36
35 CLIENT_DIR = os.path.normpath( 37 CLIENT_DIR = os.path.normpath(
36 os.path.join(test_env_bot_code.BOT_DIR, '..', '..', '..', 'client')) 38 os.path.join(test_env_bot_code.BOT_DIR, '..', '..', '..', 'client'))
37 39
38 sys.path.insert(0, os.path.join(CLIENT_DIR, 'tests')) 40 sys.path.insert(0, os.path.join(CLIENT_DIR, 'tests'))
39 import isolateserver_mock 41 import isolateserver_mock
40 42
41 43
42 def get_manifest(script=None, isolated=None, **kwargs): 44 def get_manifest(script=None, isolated=None, **kwargs):
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 expected = { 582 expected = {
581 u'exit_code': -1, 583 u'exit_code': -1,
582 u'hard_timeout': False, 584 u'hard_timeout': False,
583 u'io_timeout': False, 585 u'io_timeout': False,
584 u'must_signal_internal_failure': None, 586 u'must_signal_internal_failure': None,
585 u'version': 3, 587 u'version': 3,
586 } 588 }
587 self.assertEqual(expected, self._run_command(task_details)) 589 self.assertEqual(expected, self._run_command(task_details))
588 590
589 def test_run_command_caches(self): 591 def test_run_command_caches(self):
592 # Put a file into a named cache.
593 cache_manager = named_cache.CacheManager(os.path.join(self.root_dir, u'c'))
594 install_dir = os.path.join(self.root_dir, u'install')
595
596 with cache_manager.open():
597 cache_manager.install(install_dir, 'foo')
598 with open(os.path.join(install_dir, 'bar'), 'wb') as f:
599 f.write('thecache')
600 cache_manager.uninstall(install_dir, 'foo')
601
590 # This runs the command for real. 602 # This runs the command for real.
591 self.requests(cost_usd=1, exit_code=0); 603 self.requests(cost_usd=1, exit_code=0)
592 script = ( 604 script = (
593 'import os\n' 605 'import os\n'
594 'print "hi"\n' 606 'print "hi"\n'
595 'with open("../../result", "w") as f:\n' 607 'with open("cache_foo/bar", "rb") as f:\n'
596 ' print >> f, os.path.abspath(os.readlink("git_cache"))' 608 ' cached = f.read()\n'
609 'with open("../../result", "wb") as f:\n'
610 ' f.write(cached)\n'
611 'with open("cache_foo/bar", "wb") as f:\n'
612 ' f.write("updated_cache")\n'
597 ) 613 )
598 task_details = self.get_task_details( 614 task_details = self.get_task_details(
599 script, 615 script,
600 caches=[{'name': 'git_chromium', 'path': 'git_cache'}]) 616 caches=[{'name': 'foo', 'path': 'cache_foo'}])
601 expected = { 617 expected = {
602 u'exit_code': 0, 618 u'exit_code': 0,
603 u'hard_timeout': False, 619 u'hard_timeout': False,
604 u'io_timeout': False, 620 u'io_timeout': False,
605 u'must_signal_internal_failure': None, 621 u'must_signal_internal_failure': None,
606 u'version': task_runner.OUT_VERSION, 622 u'version': task_runner.OUT_VERSION,
607 } 623 }
608 self.assertEqual(expected, self._run_command(task_details)) 624 self.assertEqual(expected, self._run_command(task_details))
609 625
610 with open(os.path.join(self.root_dir, 'result')) as f: 626 with open(os.path.join(self.root_dir, 'result'), 'rb') as f:
611 rundir_cache_path = f.read().strip() 627 self.assertEqual('thecache', f.read())
612 named_caches = os.path.join(self.root_dir, 'c', 'named') 628
613 self.assertTrue(os.path.isdir(named_caches)) 629 with cache_manager.open():
614 named_cache_path = os.path.abspath( 630 cache_manager.install(install_dir, 'foo')
615 os.readlink(os.path.join(named_caches, 'git_chromium'))) 631 with open(os.path.join(install_dir, 'bar'), 'rb') as f:
616 self.assertEqual(rundir_cache_path, named_cache_path) 632 self.assertEqual('updated_cache', f.read())
633 cache_manager.uninstall(install_dir, 'foo')
617 634
618 def test_main(self): 635 def test_main(self):
619 def load_and_run( 636 def load_and_run(
620 manifest, swarming_server, is_grpc, cost_usd_hour, start, 637 manifest, swarming_server, is_grpc, cost_usd_hour, start,
621 json_file, run_isolated_flags, bot_file, auth_params_file): 638 json_file, run_isolated_flags, bot_file, auth_params_file):
622 self.assertEqual('foo', manifest) 639 self.assertEqual('foo', manifest)
623 self.assertEqual('http://localhost', swarming_server) 640 self.assertEqual('http://localhost', swarming_server)
624 self.assertFalse(is_grpc) 641 self.assertFalse(is_grpc)
625 self.assertEqual(3600., cost_usd_hour) 642 self.assertEqual(3600., cost_usd_hour)
626 self.assertEqual(time.time(), start) 643 self.assertEqual(time.time(), start)
(...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after
1273 fix_encoding.fix_encoding() 1290 fix_encoding.fix_encoding()
1274 if '-v' in sys.argv: 1291 if '-v' in sys.argv:
1275 unittest.TestCase.maxDiff = None 1292 unittest.TestCase.maxDiff = None
1276 logging_utils.prepare_logging(None) 1293 logging_utils.prepare_logging(None)
1277 logging_utils.set_console_level( 1294 logging_utils.set_console_level(
1278 logging.DEBUG if '-v' in sys.argv else logging.CRITICAL+1) 1295 logging.DEBUG if '-v' in sys.argv else logging.CRITICAL+1)
1279 # Fix litteral text expectation. 1296 # Fix litteral text expectation.
1280 os.environ['LANG'] = 'en_US.UTF-8' 1297 os.environ['LANG'] = 'en_US.UTF-8'
1281 os.environ['LANGUAGE'] = 'en_US.UTF-8' 1298 os.environ['LANGUAGE'] = 'en_US.UTF-8'
1282 unittest.main() 1299 unittest.main()
OLDNEW
« no previous file with comments | « appengine/swarming/local_smoke_test.py ('k') | client/named_cache.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698