summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Maw <jonathan.maw@codethink.co.uk>2018-08-20 13:35:41 +0100
committerTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2018-08-23 14:55:06 +0900
commite3cfcdeadb7ebd38018c165187db9bb819c7a05f (patch)
treea8bdc5cb1f82c89b91a22d3f7e118945d1422846
parentdd4f7ced260d63878e7f52fb3fa3c0d5591e7db8 (diff)
downloadbuildstream-e3cfcdeadb7ebd38018c165187db9bb819c7a05f.tar.gz
Add tests that cache size works
-rw-r--r--buildstream/_artifactcache/__init__.py2
-rw-r--r--tests/artifactcache/cache_size.py62
2 files changed, 63 insertions, 1 deletions
diff --git a/buildstream/_artifactcache/__init__.py b/buildstream/_artifactcache/__init__.py
index 07ed52b4b..fad483a57 100644
--- a/buildstream/_artifactcache/__init__.py
+++ b/buildstream/_artifactcache/__init__.py
@@ -17,4 +17,4 @@
# Authors:
# Tristan Van Berkom <tristan.vanberkom@codethink.co.uk>
-from .artifactcache import ArtifactCache, ArtifactCacheSpec
+from .artifactcache import ArtifactCache, ArtifactCacheSpec, CACHE_SIZE_FILE
diff --git a/tests/artifactcache/cache_size.py b/tests/artifactcache/cache_size.py
new file mode 100644
index 000000000..0d12cda8c
--- /dev/null
+++ b/tests/artifactcache/cache_size.py
@@ -0,0 +1,62 @@
+import os
+import pytest
+
+from buildstream import _yaml
+from buildstream._artifactcache import CACHE_SIZE_FILE
+
+from tests.testutils import cli, create_element_size
+
+# XXX: Currently lacking:
+# * A way to check whether it's faster to read cache size on
+# successive invocations.
+# * A way to check whether the cache size file has been read.
+
+
+def create_project(project_dir):
+ project_file = os.path.join(project_dir, "project.conf")
+ project_conf = {
+ "name": "test"
+ }
+ _yaml.dump(project_conf, project_file)
+ element_name = "test.bst"
+ create_element_size(element_name, project_dir, ".", [], 1024)
+
+
+def test_cache_size_roundtrip(cli, tmpdir):
+ # Builds (to put files in the cache), then invokes buildstream again
+ # to check nothing breaks
+
+ # Create project
+ project_dir = str(tmpdir)
+ create_project(project_dir)
+
+ # Build, to populate the cache
+ res = cli.run(project=project_dir, args=["build", "test.bst"])
+ res.assert_success()
+
+ # Show, to check that nothing breaks while reading cache size
+ res = cli.run(project=project_dir, args=["show", "test.bst"])
+ res.assert_success()
+
+
+def test_cache_size_write(cli, tmpdir):
+ # Builds (to put files in the cache), then checks a number is
+ # written to the cache size file.
+
+ project_dir = str(tmpdir)
+ create_project(project_dir)
+
+ # Artifact cache must be in a known place
+ artifactdir = os.path.join(project_dir, "artifacts")
+ cli.configure({"artifactdir": artifactdir})
+
+ # Build, to populate the cache
+ res = cli.run(project=project_dir, args=["build", "test.bst"])
+ res.assert_success()
+
+ # Inspect the artifact cache
+ sizefile = os.path.join(artifactdir, CACHE_SIZE_FILE)
+ assert os.path.isfile(sizefile)
+ with open(sizefile, "r") as f:
+ size_data = f.read()
+ size = int(size_data)