diff options
author | Jürg Billeter <j@bitron.ch> | 2019-09-10 16:25:44 +0200 |
---|---|---|
committer | bst-marge-bot <marge-bot@buildstream.build> | 2019-09-10 16:09:14 +0000 |
commit | 408414eeae9d0c9553f01a6a99fc97681d60b0c3 (patch) | |
tree | ca68e0bee75220d9c03133e0e3a04af3aac85788 /tests | |
parent | 505316c6c27478711a0cc68edb5407dce0a81e8e (diff) | |
download | buildstream-408414eeae9d0c9553f01a6a99fc97681d60b0c3.tar.gz |
tests/artifactcache/expiry.py: Add test for cache usage monitorjuerg/cache-usage
Diffstat (limited to 'tests')
-rw-r--r-- | tests/artifactcache/expiry.py | 33 |
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 |