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

Unified Diff: appengine/swarming/swarming_bot/bot_code/task_runner_test.py

Issue 2877483004: Reland "named caches: move instead of symlinking" (Closed)
Patch Set: remove wrong comment 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « appengine/swarming/local_smoke_test.py ('k') | client/named_cache.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: appengine/swarming/swarming_bot/bot_code/task_runner_test.py
diff --git a/appengine/swarming/swarming_bot/bot_code/task_runner_test.py b/appengine/swarming/swarming_bot/bot_code/task_runner_test.py
index e68a21316c5eed20cf8c83b6706331f308224168..f6da632a70ca308d9b8a11e320ad183c6bf337be 100755
--- a/appengine/swarming/swarming_bot/bot_code/task_runner_test.py
+++ b/appengine/swarming/swarming_bot/bot_code/task_runner_test.py
@@ -5,6 +5,7 @@
# that can be found in the LICENSE file.
import base64
+import contextlib
import json
import logging
import os
@@ -28,8 +29,9 @@ from utils import logging_utils
from utils import subprocess42
from libs import luci_context
import bot_auth
-import remote_client
import fake_swarming
+import named_cache
+import remote_client
import task_runner
CLIENT_DIR = os.path.normpath(
@@ -587,17 +589,35 @@ class TestTaskRunner(TestTaskRunnerBase):
self.assertEqual(expected, self._run_command(task_details))
def test_run_command_caches(self):
+ # Put a file into a named cache.
+ cache_manager = named_cache.CacheManager(os.path.join(self.root_dir, u'c'))
+ install_dir = os.path.join(self.root_dir, u'install')
+
+ @contextlib.contextmanager
+ def tmpinstall():
+ with cache_manager.open():
+ cache_manager.install(install_dir, 'foo')
+ yield
+ cache_manager.uninstall(install_dir, 'foo')
+
+ with tmpinstall(), open(os.path.join(install_dir, 'bar'), 'wb') as f:
M-A Ruel 2017/05/11 19:55:13 Why not: with cache_manager.open(): cache_manage
+ f.write('thecache')
+
# This runs the command for real.
- self.requests(cost_usd=1, exit_code=0);
+ self.requests(cost_usd=1, exit_code=0)
script = (
'import os\n'
'print "hi"\n'
- 'with open("../../result", "w") as f:\n'
- ' print >> f, os.path.abspath(os.readlink("git_cache"))'
+ 'with open("cache_foo/bar", "rb") as f:\n'
+ ' cached = f.read()\n'
+ 'with open("../../result", "wb") as f:\n'
+ ' f.write(cached)\n'
+ 'with open("cache_foo/bar", "wb") as f:\n'
+ ' f.write("updated_cache")\n'
)
task_details = self.get_task_details(
script,
- caches=[{'name': 'git_chromium', 'path': 'git_cache'}])
+ caches=[{'name': 'foo', 'path': 'cache_foo'}])
expected = {
u'exit_code': 0,
u'hard_timeout': False,
@@ -607,13 +627,11 @@ class TestTaskRunner(TestTaskRunnerBase):
}
self.assertEqual(expected, self._run_command(task_details))
- with open(os.path.join(self.root_dir, 'result')) as f:
- rundir_cache_path = f.read().strip()
- named_caches = os.path.join(self.root_dir, 'c', 'named')
- self.assertTrue(os.path.isdir(named_caches))
- named_cache_path = os.path.abspath(
- os.readlink(os.path.join(named_caches, 'git_chromium')))
- self.assertEqual(rundir_cache_path, named_cache_path)
+ with open(os.path.join(self.root_dir, 'result'), 'rb') as f:
+ self.assertEqual('thecache', f.read())
+
+ with tmpinstall(), open(os.path.join(install_dir, 'bar'), 'rb') as f:
+ self.assertEqual(f.read(), 'updated_cache')
M-A Ruel 2017/05/11 19:55:13 self.assertEqual('updated_cache', f.read())
def test_main(self):
def load_and_run(
« 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