diff options
author | Jürg Billeter <j@bitron.ch> | 2020-09-15 19:00:03 +0200 |
---|---|---|
committer | Jürg Billeter <j@bitron.ch> | 2020-09-16 11:14:33 +0200 |
commit | 851c83e76baa7c914e88d7b477ddcd8bce5b417b (patch) | |
tree | 0094651686440c20334674abd35c58547a9c0a74 /tests | |
parent | 3cfe7a1acaf2c4b6d92d26e4d5030227ccad0d50 (diff) | |
download | buildstream-851c83e76baa7c914e88d7b477ddcd8bce5b417b.tar.gz |
tests/frontend/rebuild.py: Add test_modify_and_revert
This tests that, in non-strict mode, a cached artifact matching the
strict cache key is preferred to a more recent artifact matching only
the weak cache key.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/frontend/rebuild.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/frontend/rebuild.py b/tests/frontend/rebuild.py index a4851e09a..d54eedfb9 100644 --- a/tests/frontend/rebuild.py +++ b/tests/frontend/rebuild.py @@ -41,3 +41,44 @@ def test_rebuild(datafiles, cli, strict): assert "target.bst" in built_elements else: assert "target.bst" not in built_elements + + +# Test that a cached artifact matching the strict cache key is preferred +# to a more recent artifact matching only the weak cache key. +@pytest.mark.datafiles(DATA_DIR) +@pytest.mark.parametrize("strict", ["strict", "non-strict"]) +def test_modify_and_revert(datafiles, cli, strict): + project = str(datafiles) + + # First build target and dependencies + result = cli.run(project=project, args=["build", "target.bst"]) + result.assert_success() + + # Remember cache key of first build + target_cache_key = cli.get_element_key(project, "target.bst") + + # Modify dependency + new_header_path = os.path.join(project, "files", "dev-files", "usr", "include", "new.h") + with open(new_header_path, "w") as f: + f.write("#define NEW") + + # Trigger rebuild. This will also rebuild the unmodified target as this + # follows a strict build plan. + result = cli.run(project=project, args=["build", "target.bst"]) + result.assert_success() + + assert "target.bst" in result.get_built_elements() + assert cli.get_element_key(project, "target.bst") != target_cache_key + + # Revert previous modification in dependency + os.unlink(new_header_path) + + # Rebuild again, everything should be cached. + result = cli.run(project=project, args=["build", "target.bst"]) + result.assert_success() + assert len(result.get_built_elements()) == 0 + + # Verify that cache key now again matches the first build in both + # strict and non-strict mode. + cli.configure({"projects": {"test": {"strict": strict == "strict"}}}) + assert cli.get_element_key(project, "target.bst") == target_cache_key |