summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJürg Billeter <j@bitron.ch>2020-04-19 10:34:24 +0200
committerJürg Billeter <j@bitron.ch>2020-04-20 14:27:16 +0200
commitf42205787e33174408012e5de3e3576acaab9f9b (patch)
treee6887c58808b83140bbb459568c38d0591b0a23a
parent70c4171aec75386ac2ecd889579402b17d87b7c0 (diff)
downloadbuildstream-juerg/artifact-blob-not-found.tar.gz
tests/frontend/push.py: Add test_push_after_rebuildjuerg/artifact-blob-not-found
-rw-r--r--tests/frontend/project/elements/random.bst1
-rw-r--r--tests/frontend/project/plugins/randomelement.py36
-rw-r--r--tests/frontend/push.py38
3 files changed, 74 insertions, 1 deletions
diff --git a/tests/frontend/project/elements/random.bst b/tests/frontend/project/elements/random.bst
new file mode 100644
index 000000000..2478dfa2a
--- /dev/null
+++ b/tests/frontend/project/elements/random.bst
@@ -0,0 +1 @@
+kind: randomelement
diff --git a/tests/frontend/project/plugins/randomelement.py b/tests/frontend/project/plugins/randomelement.py
new file mode 100644
index 000000000..b36b75c8a
--- /dev/null
+++ b/tests/frontend/project/plugins/randomelement.py
@@ -0,0 +1,36 @@
+import os
+
+from buildstream import Element
+
+
+class RandomElement(Element):
+ BST_VIRTUAL_DIRECTORY = True
+
+ def configure(self, node):
+ pass
+
+ def preflight(self):
+ pass
+
+ def get_unique_key(self):
+ pass
+
+ def configure_sandbox(self, sandbox):
+ pass
+
+ def stage(self, sandbox):
+ pass
+
+ def assemble(self, sandbox):
+ rootdir = sandbox.get_virtual_directory()
+ outputdir = rootdir.descend("output", create=True)
+
+ # Generate non-reproducible output
+ with outputdir.open_file("random", mode="wb") as f:
+ f.write(os.urandom(64))
+
+ return "/output"
+
+
+def setup():
+ return RandomElement
diff --git a/tests/frontend/push.py b/tests/frontend/push.py
index e9dfa2c6a..c2f52c514 100644
--- a/tests/frontend/push.py
+++ b/tests/frontend/push.py
@@ -24,10 +24,11 @@
# pylint: disable=redefined-outer-name
import os
+import shutil
import pytest
from buildstream.exceptions import ErrorDomain
-from buildstream.testing import cli # pylint: disable=unused-import
+from buildstream.testing import cli, generate_project # pylint: disable=unused-import
from tests.testutils import (
create_artifact_share,
create_element_size,
@@ -627,3 +628,38 @@ def test_push_no_strict(caplog, cli, tmpdir, datafiles, buildtrees):
args += ["artifact", "push", "--deps", "all", "target.bst"]
result = cli.run(project=project, args=args)
result.assert_success()
+
+
+# Test that push works after rebuilding an incomplete artifact
+# of a non-reproducible element.
+@pytest.mark.datafiles(DATA_DIR)
+def test_push_after_rebuild(cli, tmpdir, datafiles):
+ project = os.path.join(datafiles.dirname, datafiles.basename)
+
+ generate_project(
+ project,
+ config={
+ "element-path": "elements",
+ "plugins": [{"origin": "local", "path": "plugins", "elements": {"randomelement": 0}}],
+ },
+ )
+
+ # First build the element
+ result = cli.run(project=project, args=["build", "random.bst"])
+ result.assert_success()
+ assert cli.get_element_state(project, "random.bst") == "cached"
+
+ # Delete the artifact blobs but keep the artifact proto,
+ # i.e., now we have an incomplete artifact
+ casdir = os.path.join(cli.directory, "cas")
+ shutil.rmtree(casdir)
+ assert cli.get_element_state(project, "random.bst") != "cached"
+
+ with create_artifact_share(os.path.join(str(tmpdir), "artifactshare")) as share:
+ cli.configure({"artifacts": {"url": share.repo, "push": True}})
+
+ # Now rebuild the element and push it
+ result = cli.run(project=project, args=["build", "random.bst"])
+ result.assert_success()
+ assert result.get_pushed_elements() == ["random.bst"]
+ assert cli.get_element_state(project, "random.bst") == "cached"