summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2018-03-21 19:08:55 +0900
committerTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2018-03-21 23:38:07 +0900
commit96c5c427c0f61050dac14692bd269084d275eb9b (patch)
tree76b5d278c18416cf6a95306365d10706d6d61b75
parent28bff0991345c0e831d9fb27b9629abe486dba13 (diff)
downloadbuildstream-96c5c427c0f61050dac14692bd269084d275eb9b.tar.gz
tests/frontend/track.py: Test that we fail gracefully for post tracking errors
This tests that we handle errors from Source.get_consistency() in the post tracking state updates gracefully, one test added for a handled failure, and another test added for an unhandled/unexpected exception.
-rw-r--r--tests/frontend/consistencyerror/__init__.py0
-rw-r--r--tests/frontend/consistencyerror/bug.bst4
-rw-r--r--tests/frontend/consistencyerror/error.bst4
-rw-r--r--tests/frontend/consistencyerror/plugins/__init__.py0
-rw-r--r--tests/frontend/consistencyerror/plugins/consistencybug.py34
-rw-r--r--tests/frontend/consistencyerror/plugins/consistencyerror.py35
-rw-r--r--tests/frontend/consistencyerror/project.conf12
-rw-r--r--tests/frontend/track.py21
8 files changed, 110 insertions, 0 deletions
diff --git a/tests/frontend/consistencyerror/__init__.py b/tests/frontend/consistencyerror/__init__.py
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/tests/frontend/consistencyerror/__init__.py
diff --git a/tests/frontend/consistencyerror/bug.bst b/tests/frontend/consistencyerror/bug.bst
new file mode 100644
index 000000000..a66002046
--- /dev/null
+++ b/tests/frontend/consistencyerror/bug.bst
@@ -0,0 +1,4 @@
+kind: import
+description: An element with an unhandled exception at get_consistency time
+sources:
+- kind: consistencybug
diff --git a/tests/frontend/consistencyerror/error.bst b/tests/frontend/consistencyerror/error.bst
new file mode 100644
index 000000000..ccf11c942
--- /dev/null
+++ b/tests/frontend/consistencyerror/error.bst
@@ -0,0 +1,4 @@
+kind: import
+description: An element with a failing source at get_consistency time
+sources:
+- kind: consistencyerror
diff --git a/tests/frontend/consistencyerror/plugins/__init__.py b/tests/frontend/consistencyerror/plugins/__init__.py
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/tests/frontend/consistencyerror/plugins/__init__.py
diff --git a/tests/frontend/consistencyerror/plugins/consistencybug.py b/tests/frontend/consistencyerror/plugins/consistencybug.py
new file mode 100644
index 000000000..39eeaa852
--- /dev/null
+++ b/tests/frontend/consistencyerror/plugins/consistencybug.py
@@ -0,0 +1,34 @@
+from buildstream import Source, SourceError, Consistency
+
+
+class ConsistencyBugSource(Source):
+
+ def configure(self, node):
+ pass
+
+ def preflight(self):
+ pass
+
+ def get_unique_key(self):
+ return {}
+
+ def get_consistency(self):
+
+ # Raise an unhandled exception (not a BstError)
+ raise Exception("Something went terribly wrong")
+
+ def get_ref(self):
+ return None
+
+ def set_ref(self, ref, node):
+ pass
+
+ def fetch(self):
+ pass
+
+ def stage(self, directory):
+ pass
+
+
+def setup():
+ return ConsistencyBugSource
diff --git a/tests/frontend/consistencyerror/plugins/consistencyerror.py b/tests/frontend/consistencyerror/plugins/consistencyerror.py
new file mode 100644
index 000000000..381e9e8f1
--- /dev/null
+++ b/tests/frontend/consistencyerror/plugins/consistencyerror.py
@@ -0,0 +1,35 @@
+from buildstream import Source, SourceError, Consistency
+
+
+class ConsistencyErrorSource(Source):
+
+ def configure(self, node):
+ pass
+
+ def preflight(self):
+ pass
+
+ def get_unique_key(self):
+ return {}
+
+ def get_consistency(self):
+
+ # Raise an error unconditionally
+ raise SourceError("Something went terribly wrong",
+ reason="the-consistency-error")
+
+ def get_ref(self):
+ return None
+
+ def set_ref(self, ref, node):
+ pass
+
+ def fetch(self):
+ pass
+
+ def stage(self, directory):
+ pass
+
+
+def setup():
+ return ConsistencyErrorSource
diff --git a/tests/frontend/consistencyerror/project.conf b/tests/frontend/consistencyerror/project.conf
new file mode 100644
index 000000000..524a32134
--- /dev/null
+++ b/tests/frontend/consistencyerror/project.conf
@@ -0,0 +1,12 @@
+# Basic project configuration that doesnt override anything
+#
+name: test
+
+# Whitelist the local test Sources
+#
+plugins:
+- origin: local
+ path: plugins
+ sources:
+ consistencyerror: 0
+ consistencybug: 0
diff --git a/tests/frontend/track.py b/tests/frontend/track.py
index 80959a5a9..62514cdd7 100644
--- a/tests/frontend/track.py
+++ b/tests/frontend/track.py
@@ -289,3 +289,24 @@ def test_track_cross_junction(cli, tmpdir, datafiles, ref_storage):
# Assert that we now have a ref for the subproject element
#
assert get_subproject_element_state() == 'buildable'
+
+
+@pytest.mark.datafiles(os.path.join(TOP_DIR, 'consistencyerror'))
+def test_track_consistency_error(cli, tmpdir, datafiles):
+ project = os.path.join(datafiles.dirname, datafiles.basename)
+
+ # Track the element causing a consistency error
+ result = cli.run(project=project, args=['track', 'error.bst'])
+ result.assert_main_error(ErrorDomain.PIPELINE, None)
+ result.assert_task_error(ErrorDomain.SOURCE, 'the-consistency-error')
+
+
+@pytest.mark.datafiles(os.path.join(TOP_DIR, 'consistencyerror'))
+def test_track_consistency_bug(cli, tmpdir, datafiles):
+ project = os.path.join(datafiles.dirname, datafiles.basename)
+
+ # Track the element causing an unhandled exception
+ result = cli.run(project=project, args=['track', 'bug.bst'])
+
+ # We expect BuildStream to fail gracefully, with no recorded exception.
+ result.assert_main_error(ErrorDomain.PIPELINE, None)