summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2019-08-12 16:53:35 -0400
committerTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2019-08-31 15:05:52 +0300
commit4d36ca3a3407a29afff2006167dd83f788759ec0 (patch)
treef0df912decb57f5f32573113b1cfc81859675d32
parent9c7435bf408db49d16915e6d808c6f746232be3b (diff)
downloadbuildstream-4d36ca3a3407a29afff2006167dd83f788759ec0.tar.gz
tests/frontend/show.py: Test that strict dependencies behave as expected
This tests that the target which depends on a common dependency strictly in non strict mode needs to be rebuilt after this common dependency changes, while it is not the case when depending on the same common target non strictly. This is a regression test for #254
-rw-r--r--tests/frontend/show.py54
-rw-r--r--tests/frontend/strict-depends/elements/base.bst5
-rw-r--r--tests/frontend/strict-depends/elements/non-strict-depends.bst4
-rw-r--r--tests/frontend/strict-depends/elements/strict-depends.bst5
-rw-r--r--tests/frontend/strict-depends/files/hello.txt1
-rw-r--r--tests/frontend/strict-depends/project.conf2
6 files changed, 71 insertions, 0 deletions
diff --git a/tests/frontend/show.py b/tests/frontend/show.py
index 0aa720681..0d444a925 100644
--- a/tests/frontend/show.py
+++ b/tests/frontend/show.py
@@ -560,3 +560,57 @@ def test_max_jobs(cli, datafiles, cli_value, config_value):
else:
# Check that we got the explicitly set value
assert loaded_value == int(expected_value)
+
+
+# This tests that cache keys behave as expected when
+# dependencies have been specified as `strict` and
+# when building in strict mode.
+#
+# This test will:
+#
+# * Build the target once (and assert that it is cached)
+# * Modify some local files which are imported
+# by an import element which the target depends on
+# * Assert that the cached state of the target element
+# is as expected
+#
+# We run the test twice, once with an element which strict
+# depends on the changing import element, and one which
+# depends on it regularly.
+#
+@pytest.mark.datafiles(os.path.join(DATA_DIR, 'strict-depends'))
+@pytest.mark.parametrize("target, expected_state", [
+ ("non-strict-depends.bst", "cached"),
+ ("strict-depends.bst", "waiting"),
+])
+def test_strict_dependencies(cli, datafiles, target, expected_state):
+ project = str(datafiles)
+
+ # Configure non strict mode, this will have
+ # an effect on the build and the `bst show`
+ # commands run via cli.get_element_states()
+ cli.configure({
+ 'projects': {
+ 'test': {
+ 'strict': False
+ }
+ }
+ })
+
+ result = cli.run(project=project, silent=True, args=['build', target])
+ result.assert_success()
+
+ states = cli.get_element_states(project, ['base.bst', target])
+ assert states['base.bst'] == 'cached'
+ assert states[target] == 'cached'
+
+ # Now modify the file, effectively causing the common base.bst
+ # dependency to change it's cache key
+ hello_path = os.path.join(project, 'files', 'hello.txt')
+ with open(hello_path, 'w') as f:
+ f.write("Goodbye")
+
+ # Now assert that we have the states we expect as a result
+ states = cli.get_element_states(project, ['base.bst', target])
+ assert states['base.bst'] == 'buildable'
+ assert states[target] == expected_state
diff --git a/tests/frontend/strict-depends/elements/base.bst b/tests/frontend/strict-depends/elements/base.bst
new file mode 100644
index 000000000..ed6197699
--- /dev/null
+++ b/tests/frontend/strict-depends/elements/base.bst
@@ -0,0 +1,5 @@
+kind: import
+
+sources:
+- kind: local
+ path: files
diff --git a/tests/frontend/strict-depends/elements/non-strict-depends.bst b/tests/frontend/strict-depends/elements/non-strict-depends.bst
new file mode 100644
index 000000000..9ab119bde
--- /dev/null
+++ b/tests/frontend/strict-depends/elements/non-strict-depends.bst
@@ -0,0 +1,4 @@
+kind: stack
+
+build-depends:
+- base.bst
diff --git a/tests/frontend/strict-depends/elements/strict-depends.bst b/tests/frontend/strict-depends/elements/strict-depends.bst
new file mode 100644
index 000000000..1e4e29414
--- /dev/null
+++ b/tests/frontend/strict-depends/elements/strict-depends.bst
@@ -0,0 +1,5 @@
+kind: stack
+
+build-depends:
+- filename: base.bst
+ strict: true
diff --git a/tests/frontend/strict-depends/files/hello.txt b/tests/frontend/strict-depends/files/hello.txt
new file mode 100644
index 000000000..f62144808
--- /dev/null
+++ b/tests/frontend/strict-depends/files/hello.txt
@@ -0,0 +1 @@
+pony
diff --git a/tests/frontend/strict-depends/project.conf b/tests/frontend/strict-depends/project.conf
new file mode 100644
index 000000000..627522526
--- /dev/null
+++ b/tests/frontend/strict-depends/project.conf
@@ -0,0 +1,2 @@
+name: test
+element-path: elements