summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2019-01-20 12:52:16 -0500
committerTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2019-04-14 16:25:19 +0900
commit66dfaa11a71936d91532bf1715ff383ad178162c (patch)
treef9f035e7f41d9d057a472b07767382be37d562c3 /tests
parent6f9c882d56d2b0b062829c4b0af05549bc669f22 (diff)
downloadbuildstream-66dfaa11a71936d91532bf1715ff383ad178162c.tar.gz
_artifactcache.py: Refactored to use utils._get_volume_size()
This will benefit from a better UtilError being raised, and and turns the artifact cache's local function into a one liner. The loop which finds the first existing directory in the given path has been removed, being meaningless due to the call to os.makedirs() in ArtifactCache.__init__(). The local function was renamed to _get_cache_volume_size() and no longer takes any arguments, which is more suitable for the function as it serves as a testing override surface for unittest.mock(). The following test cases which use the function to override the ArtifactCache behavior have been updated to use the new overridable function name: tests/artifactcache/cache_size.py tests/artifactcache/expiry.py
Diffstat (limited to 'tests')
-rw-r--r--tests/artifactcache/cache_size.py26
-rw-r--r--tests/artifactcache/expiry.py32
2 files changed, 56 insertions, 2 deletions
diff --git a/tests/artifactcache/cache_size.py b/tests/artifactcache/cache_size.py
index 0d12cda8c..8e47f9fb6 100644
--- a/tests/artifactcache/cache_size.py
+++ b/tests/artifactcache/cache_size.py
@@ -60,3 +60,29 @@ def test_cache_size_write(cli, tmpdir):
with open(sizefile, "r") as f:
size_data = f.read()
size = int(size_data)
+
+
+def test_quota_over_1024T(cli, tmpdir):
+ KiB = 1024
+ MiB = (KiB * 1024)
+ GiB = (MiB * 1024)
+ TiB = (GiB * 1024)
+
+ cli.configure({
+ 'cache': {
+ 'quota': 2048 * TiB
+ }
+ })
+ project = tmpdir.join("main")
+ os.makedirs(str(project))
+ _yaml.dump({'name': 'main'}, str(project.join("project.conf")))
+
+ volume_space_patch = mock.patch(
+ "buildstream._artifactcache.ArtifactCache._get_cache_volume_size",
+ autospec=True,
+ return_value=(1025 * TiB, 1025 * TiB)
+ )
+
+ with volume_space_patch:
+ result = cli.run(project, args=["build", "file.bst"])
+ result.assert_main_error(ErrorDomain.ARTIFACT, 'insufficient-storage-for-quota')
diff --git a/tests/artifactcache/expiry.py b/tests/artifactcache/expiry.py
index f8b928cbf..68a1c87cd 100644
--- a/tests/artifactcache/expiry.py
+++ b/tests/artifactcache/expiry.py
@@ -303,8 +303,36 @@ def test_invalid_cache_quota(cli, datafiles, tmpdir, quota, success):
}
})
- res = cli.run(project=project, args=['workspace', 'list'])
- if success:
+ # We patch how we get space information
+ # Ideally we would instead create a FUSE device on which we control
+ # everything.
+ # If the value is a percentage, we fix the current values to take into
+ # account the block size, since this is important in how we compute the size
+
+ if quota.endswith("%"): # We set the used space at 60% of total space
+ stats = os.statvfs(".")
+ free_space = 0.6 * stats.f_bsize * stats.f_blocks
+ total_space = stats.f_bsize * stats.f_blocks
+ else:
+ free_space = 6000
+ total_space = 10000
+
+ volume_space_patch = mock.patch(
+ "buildstream._artifactcache.ArtifactCache._get_cache_volume_size",
+ autospec=True,
+ return_value=(total_space, free_space),
+ )
+
+ cache_size_patch = mock.patch(
+ "buildstream._artifactcache.ArtifactCache.get_cache_size",
+ autospec=True,
+ return_value=0,
+ )
+
+ with volume_space_patch, cache_size_patch:
+ res = cli.run(project=project, args=['workspace', 'list'])
+
+ if err_domain == 'success':
res.assert_success()
else:
res.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.INVALID_DATA)