summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJürg Billeter <j@bitron.ch>2019-09-10 16:25:44 +0200
committerbst-marge-bot <marge-bot@buildstream.build>2019-09-10 16:09:14 +0000
commit408414eeae9d0c9553f01a6a99fc97681d60b0c3 (patch)
treeca68e0bee75220d9c03133e0e3a04af3aac85788
parent505316c6c27478711a0cc68edb5407dce0a81e8e (diff)
downloadbuildstream-juerg/cache-usage.tar.gz
tests/artifactcache/expiry.py: Add test for cache usage monitorjuerg/cache-usage
-rw-r--r--tests/artifactcache/expiry.py33
1 files changed, 33 insertions, 0 deletions
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