summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbst-marge-bot <marge-bot@buildstream.build>2019-09-10 17:08:49 +0000
committerbst-marge-bot <marge-bot@buildstream.build>2019-09-10 17:08:49 +0000
commit3eedd7a7a5db75650085275c63596a54f412feab (patch)
treeca68e0bee75220d9c03133e0e3a04af3aac85788
parent8261dfa594bf0554be85e4ce6732cd9fe4ff3d44 (diff)
parent408414eeae9d0c9553f01a6a99fc97681d60b0c3 (diff)
downloadbuildstream-3eedd7a7a5db75650085275c63596a54f412feab.tar.gz
Merge branch 'juerg/cache-usage' into 'master'
cascache.py: Fix cache usage monitor on Python older than 3.7 Closes #1131 See merge request BuildStream/buildstream!1597
-rw-r--r--src/buildstream/_cas/cascache.py5
-rw-r--r--tests/artifactcache/expiry.py33
2 files changed, 36 insertions, 2 deletions
diff --git a/src/buildstream/_cas/cascache.py b/src/buildstream/_cas/cascache.py
index 2d93f0527..1f687669b 100644
--- a/src/buildstream/_cas/cascache.py
+++ b/src/buildstream/_cas/cascache.py
@@ -22,6 +22,7 @@ import os
import stat
import errno
import contextlib
+import ctypes
import multiprocessing
import shutil
import signal
@@ -931,8 +932,8 @@ class _CASCacheUsageMonitor:
self.cas = cas
# Shared memory (64-bit signed integer) for current disk usage and quota
- self._disk_usage = multiprocessing.Value('q', -1)
- self._disk_quota = multiprocessing.Value('q', -1)
+ self._disk_usage = multiprocessing.Value(ctypes.c_longlong, -1)
+ self._disk_quota = multiprocessing.Value(ctypes.c_longlong, -1)
# multiprocessing.Process will fork without exec on Unix.
# This can't be allowed with background threads or open gRPC channels.
diff --git a/tests/artifactcache/expiry.py b/tests/artifactcache/expiry.py
index 3e252fe2d..d33034813 100644
--- a/tests/artifactcache/expiry.py
+++ b/tests/artifactcache/expiry.py
@@ -21,9 +21,11 @@
# pylint: disable=redefined-outer-name
import os
+import time
import pytest
+from buildstream._cas import CASCache
from buildstream._exceptions import ErrorDomain, LoadErrorReason
from buildstream.testing import cli # pylint: disable=unused-import
@@ -36,6 +38,22 @@ DATA_DIR = os.path.join(
)
+def get_cache_usage(directory):
+ cas_cache = CASCache(directory)
+ try:
+ wait = 0.1
+ for _ in range(0, int(5 / wait)):
+ used_size = cas_cache.get_cache_usage().used_size
+ if used_size is not None:
+ return used_size
+ time.sleep(wait)
+
+ assert False, "Unable to retrieve cache usage"
+ return None
+ finally:
+ cas_cache.release_resources()
+
+
# Ensure that the cache successfully removes an old artifact if we do
# not have enough space left.
@pytest.mark.datafiles(DATA_DIR)
@@ -388,3 +406,18 @@ def test_cleanup_first(cli, datafiles):
states = cli.get_element_states(project, ['target.bst', 'target2.bst'])
assert states['target.bst'] != 'cached'
assert states['target2.bst'] == 'cached'
+
+
+@pytest.mark.datafiles(DATA_DIR)
+def test_cache_usage_monitor(cli, tmpdir, datafiles):
+ project = str(datafiles)
+ element_path = 'elements'
+
+ assert get_cache_usage(cli.directory) == 0
+
+ ELEMENT_SIZE = 1000000
+ create_element_size('target.bst', project, element_path, [], ELEMENT_SIZE)
+ res = cli.run(project=project, args=['build', 'target.bst'])
+ res.assert_success()
+
+ assert get_cache_usage(cli.directory) >= ELEMENT_SIZE