You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by tv...@apache.org on 2022/07/20 07:24:29 UTC

[buildstream] branch tristan/retry-failed-build-non-strict created (now 7042f1091)

This is an automated email from the ASF dual-hosted git repository.

tvb pushed a change to branch tristan/retry-failed-build-non-strict
in repository https://gitbox.apache.org/repos/asf/buildstream.git


      at 7042f1091 tests/integration/cachedfail.py: Test that failed builds are retried in non-strict mode

This branch includes the following new commits:

     new ad6654958 element.py: In non-strict mode, retry failed builds whenever dependencies change
     new 7042f1091 tests/integration/cachedfail.py: Test that failed builds are retried in non-strict mode

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[buildstream] 02/02: tests/integration/cachedfail.py: Test that failed builds are retried in non-strict mode

Posted by tv...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

tvb pushed a commit to branch tristan/retry-failed-build-non-strict
in repository https://gitbox.apache.org/repos/asf/buildstream.git

commit 7042f10915e2f82e269caea8a145d66ff392e2d9
Author: Tristan van Berkom <tr...@codethink.co.uk>
AuthorDate: Wed Jul 20 13:07:11 2022 +0900

    tests/integration/cachedfail.py: Test that failed builds are retried in non-strict mode
    
    If the dependencies of a failed build have changed then a failed build in
    non-strict mode will be retried.
---
 tests/integration/cachedfail.py | 116 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 116 insertions(+)

diff --git a/tests/integration/cachedfail.py b/tests/integration/cachedfail.py
index a2157796e..b94b224d9 100644
--- a/tests/integration/cachedfail.py
+++ b/tests/integration/cachedfail.py
@@ -17,7 +17,9 @@
 # pylint: disable=redefined-outer-name
 
 import os
+import glob
 import pytest
+from contextlib import ExitStack
 
 from buildstream import utils, _yaml
 from buildstream.exceptions import ErrorDomain
@@ -256,3 +258,117 @@ def test_host_tools_errors_are_not_cached(cli, datafiles, tmp_path):
     result2 = cli.run(project=project, args=["build", "element.bst"])
     result2.assert_success()
     assert cli.get_element_state(project, "element.bst") == "cached"
+
+
+# Tests that failed builds will be retried in strict mode when dependencies have changed.
+#
+# This test ensures:
+#   o Fixing a dependency such that the reverse dependency will succeed, gets automatically retried
+#   o A subsequent retry of the same failed build will not trigger a retry attempt
+#   o The same behavior is observed when a failed build artifact is downloaded from a remote cache
+#
+@pytest.mark.datafiles(DATA_DIR)
+@pytest.mark.skipif(not HAVE_SANDBOX, reason="Only available with a functioning sandbox")
+@pytest.mark.parametrize("use_share", (False, True), ids=["local-cache", "pull-failed-artifact"])
+@pytest.mark.parametrize("retry", (True, False), ids=["retry", "no-retry"])
+def test_nonstrict_retry_failed(cli, tmpdir, datafiles, use_share, retry):
+    project = str(datafiles)
+    dep_path = os.path.join(project, "elements", "dep.bst")
+    target_path = os.path.join(project, "elements", "target.bst")
+
+    # Use separate cache directories for each iteration of this test
+    # even though we're using cli_integration
+    cli.configure(
+        {
+            "cachedir": cli.directory,
+        }
+    )
+
+    def generate_dep(cause_fail):
+        if cause_fail:
+            touch_file = "bar"
+        else:
+            touch_file = "foo"
+
+        return {
+            "kind": "manual",
+            "depends": ["base.bst"],
+            "config": {
+                "install-commands": [
+                    "touch %{install-root}/" + touch_file,
+                ],
+            },
+        }
+
+    def generate_target():
+        return {
+            "kind": "manual",
+            "depends": [
+                "dep.bst",
+            ],
+            "config": {
+                "build-commands": [
+                    "test -e /foo",
+                ],
+            },
+        }
+
+    with ExitStack() as stack:
+
+        if use_share:
+            share = stack.enter_context(create_artifact_share(os.path.join(str(tmpdir), "artifactshare")))
+            cli.configure({"artifacts": {"servers": [{"url": share.repo, "push": True}]}})
+
+        dep = generate_dep(True)
+        target = generate_target()
+        _yaml.roundtrip_dump(dep, dep_path)
+        _yaml.roundtrip_dump(target, target_path)
+
+        # Try to build it, this should result in caching a failure of the target
+        result = cli.run(project=project, args=["--no-strict", "build", "target.bst"])
+        result.assert_main_error(ErrorDomain.STREAM, None)
+
+        # Assert that it's cached in a failed artifact
+        assert cli.get_element_state(project, "target.bst") == "failed"
+
+        if use_share:
+            # Ensure that the target.bst has been shared, this is needed because of:
+            #     https://github.com/apache/buildstream/issues/534
+            result = cli.run(project=project, args=["--no-strict", "artifact", "push", "target.bst"])
+            result.assert_success()
+
+            # Delete the local cache, provoke pulling of the failed build
+            cli.remove_artifact_from_cache(project, "target.bst")
+
+            # Assert that the failed build has been removed
+            assert cli.get_element_state(project, "target.bst") == "buildable"
+
+        # Regenerate the dependency so that the target would succeed to build, if the
+        # test is configured to test a retry
+        if retry:
+            dep = generate_dep(False)
+            _yaml.roundtrip_dump(dep, dep_path)
+
+        # Even though we are in non-strict mode, the failed build should be retried
+        result = cli.run(project=project, args=["--no-strict", "build", "target.bst"])
+
+        # If we did not modify the cache key, we want to assert that we did not
+        # in fact attempt to rebuild the failed artifact.
+        #
+        # Since the UX is very similar, we'll distinguish this by counting the number of
+        # build logs which were produced.
+        #
+        logdir = os.path.join(cli.directory, "logs", "test", "target")
+        build_logs = glob.glob("{}/*-build.*.log".format(logdir))
+        if retry:
+            result.assert_success()
+            assert len(build_logs) == 2
+        else:
+            result.assert_main_error(ErrorDomain.STREAM, None)
+            assert len(build_logs) == 1
+
+        if use_share:
+            # Assert that we did indeed go through the motions of downloading the failed
+            # build, and possibly discarded the failed artifact if the strong key did not match
+            #
+            assert "target.bst" in result.get_pulled_elements()


[buildstream] 01/02: element.py: In non-strict mode, retry failed builds whenever dependencies change

Posted by tv...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

tvb pushed a commit to branch tristan/retry-failed-build-non-strict
in repository https://gitbox.apache.org/repos/asf/buildstream.git

commit ad66549587eea81bf0d8a5a2cc95148771c15d92
Author: Tristan van Berkom <tr...@codethink.co.uk>
AuthorDate: Wed Jul 20 12:18:13 2022 +0900

    element.py: In non-strict mode, retry failed builds whenever dependencies change
    
    Fixes #1460
---
 src/buildstream/element.py | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/src/buildstream/element.py b/src/buildstream/element.py
index 57e5b7564..4fa74e2c3 100644
--- a/src/buildstream/element.py
+++ b/src/buildstream/element.py
@@ -1831,6 +1831,10 @@ class Element(Plugin):
     #
     # Load artifact from cache or pull it from remote artifact repository.
     #
+    # Args:
+    #    pull (bool): Whether to attempt to pull the artifact
+    #    strict (bool|None): Force strict/non-strict operation
+    #
     # Returns: True if the artifact has been downloaded, False otherwise
     #
     def _load_artifact(self, *, pull, strict=None):
@@ -1874,6 +1878,21 @@ class Element(Plugin):
         # Attempt to pull artifact with the weak cache key
         pulled = pull and artifact.pull(pull_buildtrees=pull_buildtrees)
 
+        # In non-strict mode we ignore a failed artifact unless it has the expected strong key
+        #
+        # This ensures that failed builds will be retried whenever dependencies have changed.
+        if artifact.cached() and artifact.strong_key != self.__cache_key:
+            success, _, _ = artifact.load_build_result()
+            if not success:
+                artifact = Artifact(
+                    self,
+                    context,
+                    strict_key=self.__strict_cache_key,
+                    weak_key=self.__weak_cache_key,
+                )
+                artifact._cached = False
+                pulled = False
+
         self.__artifact = artifact
         return pulled