From 9c2bbe3c3871db3a33f81e48987f6d473f97b136 Mon Sep 17 00:00:00 2001 From: Darius Makovsky Date: Mon, 21 Oct 2019 13:36:56 +0100 Subject: cascache.py: instantiate usage monitor early tests: manually close channels when interacting with the cache cascache.py: disable the usage monitor if start method is spawn --- src/buildstream/_cas/cascache.py | 24 ++++++++++++++++-------- tests/artifactcache/pull.py | 2 ++ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/buildstream/_cas/cascache.py b/src/buildstream/_cas/cascache.py index 83b8e8539..2a2313097 100644 --- a/src/buildstream/_cas/cascache.py +++ b/src/buildstream/_cas/cascache.py @@ -79,6 +79,11 @@ class CASCache(): os.makedirs(os.path.join(self.casdir, 'objects'), exist_ok=True) os.makedirs(self.tmpdir, exist_ok=True) + self._casd_channel = None + self._casd_cas = None + self._local_cas = None + self._cache_usage_monitor = None + if casd: # Place socket in global/user temporary directory to avoid hitting # the socket path length limit. @@ -107,14 +112,11 @@ class CASCache(): with _signals.blocked([signal.SIGINT], ignore=False): self._casd_process = subprocess.Popen( casd_args, cwd=path, stdout=logfile_fp, stderr=subprocess.STDOUT) + + self._cache_usage_monitor = _CASCacheUsageMonitor.create_cas_usage_monitor(self) else: self._casd_process = None - self._casd_channel = None - self._casd_cas = None - self._local_cas = None - self._cache_usage_monitor = None - def __getstate__(self): state = self.__dict__.copy() @@ -1045,9 +1047,6 @@ class CASCache(): # (CASCacheUsage): The current status # def get_cache_usage(self): - if not self._cache_usage_monitor: - self._cache_usage_monitor = _CASCacheUsageMonitor(self) - return self._cache_usage_monitor.get_cache_usage() # get_casd_process() @@ -1100,6 +1099,15 @@ class _CASCacheUsage(): # buildbox-casd. # class _CASCacheUsageMonitor: + + # FIXME: SemaphoreTracker crashes when triggered via spawn and used in + # tests using fork. + @classmethod + def create_cas_usage_monitor(cls, cas): + if multiprocessing.get_start_method() == 'spawn': + return None + return cls(cas) + def __init__(self, cas): self.cas = cas diff --git a/tests/artifactcache/pull.py b/tests/artifactcache/pull.py index 2e33af3ac..c32ed94a0 100644 --- a/tests/artifactcache/pull.py +++ b/tests/artifactcache/pull.py @@ -177,6 +177,8 @@ def test_pull_tree(cli, tmpdir, datafiles): cli.remove_artifact_from_cache(project_dir, 'target.bst') # Assert that we are not cached locally anymore + artifactcache.close_grpc_channels() + cas.close_grpc_channels() assert cli.get_element_state(project_dir, 'target.bst') != 'cached' tree_digest = remote_execution_pb2.Digest(hash=tree_hash, -- cgit v1.2.1