Skip to content

Commit

Permalink
Reland "named caches: move instead of symlinking"
Browse files Browse the repository at this point in the history
This relands d1ab255
with fixed tests.

BUG=715326

Review-Url: https://codereview.chromium.org/2877483004
  • Loading branch information
nodirt authored and Commit bot committed May 11, 2017
1 parent b1e8e30 commit b551d1c
Show file tree
Hide file tree
Showing 6 changed files with 290 additions and 175 deletions.
3 changes: 0 additions & 3 deletions appengine/swarming/local_smoke_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,9 +638,6 @@ def test_local_cache(self):
# directory. Each time it's the exact same script.
script = '\n'.join((
'import os, shutil, sys',
'if not os.path.islink("p/b"):',
' print("p/b is not a symlink")',
' sys.exit(1)',
'p = "p/b/a.txt"',
'if not os.path.isfile(p):',
' with open(p, "wb") as f:',
Expand Down
41 changes: 29 additions & 12 deletions appengine/swarming/swarming_bot/bot_code/task_runner_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# that can be found in the LICENSE file.

import base64
import contextlib
import json
import logging
import os
Expand All @@ -28,8 +29,9 @@
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(
Expand Down Expand Up @@ -587,17 +589,31 @@ def test_run_command_canceled(self):
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')

with cache_manager.open():
cache_manager.install(install_dir, 'foo')
with open(os.path.join(install_dir, 'bar'), 'wb') as f:
f.write('thecache')
cache_manager.uninstall(install_dir, 'foo')

# 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,
Expand All @@ -607,13 +623,14 @@ def test_run_command_caches(self):
}
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 cache_manager.open():
cache_manager.install(install_dir, 'foo')
with open(os.path.join(install_dir, 'bar'), 'rb') as f:
self.assertEqual('updated_cache', f.read())
cache_manager.uninstall(install_dir, 'foo')

def test_main(self):
def load_and_run(
Expand Down
Loading

0 comments on commit b551d1c

Please sign in to comment.