summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBenjamin Schubert <bschubert15@bloomberg.net>2019-11-27 16:26:37 +0000
committerBenjamin Schubert <bschubert15@bloomberg.net>2020-01-16 16:33:19 +0000
commit4a47af24fca8aeb6c0c0fe6bd754712ecce5211d (patch)
tree08f72ea7bbc2979637900b1bcaeb8aa798d41c52 /tests
parent93ebe4992c32b2588ae213a98c3e05d60c974a00 (diff)
downloadbuildstream-4a47af24fca8aeb6c0c0fe6bd754712ecce5211d.tar.gz
source.py: Add a new 'is_resolved' to get whether a source is resolved.
`get_consistency` is coarse grained and hard to optimize, in addition to being un-userfriendly. This adds a new `is_resolved` that has for default implementation `get_ref() is not None`, which is true for most sources in BuildStream. Sources for which this is not true can override the method to give a more accurate description. Checking for this before looking whether the source is cached can reduce the amount of work necessary in some pipeline and opens the door for more optimizations and the removal of the source state check.
Diffstat (limited to 'tests')
-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/project_key_test/plugins/sources/key-test.py5
5 files changed, 16 insertions, 1 deletions
diff --git a/tests/frontend/consistencyerror/plugins/consistencybug.py b/tests/frontend/consistencyerror/plugins/consistencybug.py
index c442d883a..c4a3217ec 100644
--- a/tests/frontend/consistencyerror/plugins/consistencybug.py
+++ b/tests/frontend/consistencyerror/plugins/consistencybug.py
@@ -11,6 +11,9 @@ class ConsistencyBugSource(Source):
def get_unique_key(self):
return {}
+ def is_resolved(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 125baf39c..d7433e368 100644
--- a/tests/frontend/consistencyerror/plugins/consistencyerror.py
+++ b/tests/frontend/consistencyerror/plugins/consistencyerror.py
@@ -11,6 +11,9 @@ class ConsistencyErrorSource(Source):
def get_unique_key(self):
return {}
+ def is_resolved(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 51bfe1049..d634adfa3 100644
--- a/tests/frontend/project/sources/fetch_source.py
+++ b/tests/frontend/project/sources/fetch_source.py
@@ -66,6 +66,9 @@ class FetchSource(Source):
def get_unique_key(self):
return {"urls": self.original_urls, "output_file": self.output_file}
+ def is_resolved(self):
+ return True
+
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 623ab19ab..5f05b592b 100644
--- a/tests/sources/no-fetch-cached/plugins/sources/always_cached.py
+++ b/tests/sources/no-fetch-cached/plugins/sources/always_cached.py
@@ -20,6 +20,9 @@ class AlwaysCachedSource(Source):
def get_unique_key(self):
return None
+ def is_resolved(self):
+ return True
+
def get_consistency(self):
return Consistency.CACHED
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 428846a3e..30256929c 100644
--- a/tests/sources/project_key_test/plugins/sources/key-test.py
+++ b/tests/sources/project_key_test/plugins/sources/key-test.py
@@ -11,7 +11,10 @@ class KeyTest(Source):
pass
def configure(self, node):
- self.ref = node.get_bool("ref", False)
+ if node.get_scalar("ref", None).is_none():
+ self.ref = None
+ else:
+ self.ref = True
def get_unique_key(self):
assert self.ref