summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBenjamin Schubert <bschubert15@bloomberg.net>2019-11-28 10:59:52 +0000
committerBenjamin Schubert <bschubert15@bloomberg.net>2020-01-16 16:33:19 +0000
commit3be6d07753599ef54b9e80ac066571632e217ce2 (patch)
treee14db9bba2d32ddb2840ab5513afde5b1ece2055 /tests
parent4a47af24fca8aeb6c0c0fe6bd754712ecce5211d (diff)
downloadbuildstream-3be6d07753599ef54b9e80ac066571632e217ce2.tar.gz
source.py: Remove the reliance on consistency to get whether a source is cached
This removes the need to use consistency in Sources, by asking explicitely whether the source is cached or not. This introduces a new public method on source: `is_cached` that needs implementation and that should return whether the source has a local copy or not. - On fetch, also reset whether the source was cached or set if as cached when we know it was. - Validate the cache's source after fetching it This doesn't need to be run in the scheduler's process and can be offloaded to the child, which will allow better multiprocessing
Diffstat (limited to 'tests')
-rw-r--r--tests/frontend/consistencyerror/bug.bst2
-rw-r--r--tests/frontend/consistencyerror/error.bst2
-rw-r--r--tests/frontend/consistencyerror/plugins/consistencybug.py3
-rw-r--r--tests/frontend/consistencyerror/plugins/consistencyerror.py3
-rw-r--r--tests/frontend/project/sources/fetch_source.py3
-rw-r--r--tests/sources/no-fetch-cached/plugins/sources/always_cached.py3
-rw-r--r--tests/sources/previous_source_access/plugins/sources/foo_transform.py3
-rw-r--r--tests/sources/project_key_test/plugins/sources/key-test.py3
8 files changed, 20 insertions, 2 deletions
diff --git a/tests/frontend/consistencyerror/bug.bst b/tests/frontend/consistencyerror/bug.bst
index a66002046..5639abee2 100644
--- a/tests/frontend/consistencyerror/bug.bst
+++ b/tests/frontend/consistencyerror/bug.bst
@@ -1,4 +1,4 @@
kind: import
-description: An element with an unhandled exception at get_consistency time
+description: An element with an unhandled exception in checking whether it is cached or not
sources:
- kind: consistencybug
diff --git a/tests/frontend/consistencyerror/error.bst b/tests/frontend/consistencyerror/error.bst
index ccf11c942..e377aa97a 100644
--- a/tests/frontend/consistencyerror/error.bst
+++ b/tests/frontend/consistencyerror/error.bst
@@ -1,4 +1,4 @@
kind: import
-description: An element with a failing source at get_consistency time
+description: An element with a failing source when checking whether it is cached or not
sources:
- kind: consistencyerror
diff --git a/tests/frontend/consistencyerror/plugins/consistencybug.py b/tests/frontend/consistencyerror/plugins/consistencybug.py
index c4a3217ec..7f0bd9211 100644
--- a/tests/frontend/consistencyerror/plugins/consistencybug.py
+++ b/tests/frontend/consistencyerror/plugins/consistencybug.py
@@ -14,6 +14,9 @@ class ConsistencyBugSource(Source):
def is_resolved(self):
return True
+ def is_cached(self):
+ return True
+
def get_consistency(self):
# Raise an unhandled exception (not a BstError)
diff --git a/tests/frontend/consistencyerror/plugins/consistencyerror.py b/tests/frontend/consistencyerror/plugins/consistencyerror.py
index d7433e368..523ac0b6f 100644
--- a/tests/frontend/consistencyerror/plugins/consistencyerror.py
+++ b/tests/frontend/consistencyerror/plugins/consistencyerror.py
@@ -14,6 +14,9 @@ class ConsistencyErrorSource(Source):
def is_resolved(self):
return True
+ def is_cached(self):
+ return True
+
def get_consistency(self):
# Raise an error unconditionally
diff --git a/tests/frontend/project/sources/fetch_source.py b/tests/frontend/project/sources/fetch_source.py
index d634adfa3..60b4ba95d 100644
--- a/tests/frontend/project/sources/fetch_source.py
+++ b/tests/frontend/project/sources/fetch_source.py
@@ -69,6 +69,9 @@ class FetchSource(Source):
def is_resolved(self):
return True
+ def is_cached(self) -> bool:
+ return self.get_consistency() == Consistency.CACHED
+
def get_consistency(self):
if not os.path.exists(self.output_file):
return Consistency.RESOLVED
diff --git a/tests/sources/no-fetch-cached/plugins/sources/always_cached.py b/tests/sources/no-fetch-cached/plugins/sources/always_cached.py
index 5f05b592b..6267a99eb 100644
--- a/tests/sources/no-fetch-cached/plugins/sources/always_cached.py
+++ b/tests/sources/no-fetch-cached/plugins/sources/always_cached.py
@@ -23,6 +23,9 @@ class AlwaysCachedSource(Source):
def is_resolved(self):
return True
+ def is_cached(self):
+ return True
+
def get_consistency(self):
return Consistency.CACHED
diff --git a/tests/sources/previous_source_access/plugins/sources/foo_transform.py b/tests/sources/previous_source_access/plugins/sources/foo_transform.py
index 906a8f6be..c59c81e63 100644
--- a/tests/sources/previous_source_access/plugins/sources/foo_transform.py
+++ b/tests/sources/previous_source_access/plugins/sources/foo_transform.py
@@ -39,6 +39,9 @@ class FooTransformSource(Source):
def get_unique_key(self):
return (self.ref,)
+ def is_cached(self):
+ return self.get_consistency() == Consistency.CACHED
+
def get_consistency(self):
if self.ref is None:
return Consistency.INCONSISTENT
diff --git a/tests/sources/project_key_test/plugins/sources/key-test.py b/tests/sources/project_key_test/plugins/sources/key-test.py
index 30256929c..98dd380ef 100644
--- a/tests/sources/project_key_test/plugins/sources/key-test.py
+++ b/tests/sources/project_key_test/plugins/sources/key-test.py
@@ -20,6 +20,9 @@ class KeyTest(Source):
assert self.ref
return "abcdefg"
+ def is_cached(self):
+ return False
+
def get_consistency(self):
if self.ref:
return Consistency.RESOLVED