diff options
author | Sascha Roloff <sascha.roloff@huawei.com> | 2024-01-19 15:39:17 +0100 |
---|---|---|
committer | Sascha Roloff <sascha.roloff@huawei.com> | 2024-01-19 18:06:05 +0100 |
commit | 682f5d7ab958b2d635c21f0b083641ba1b03fe39 (patch) | |
tree | e2e3dfd2dc54f03fb95cdd4e736ebd3b80c86056 /test | |
parent | 399f75c8b63c3214938e03d5d9b532a5dd7a4000 (diff) | |
download | justbuild-682f5d7ab958b2d635c21f0b083641ba1b03fe39.tar.gz |
Add test case to check tree invariant in just execute
Diffstat (limited to 'test')
-rw-r--r-- | test/buildtool/execution_api/TARGETS | 5 | ||||
-rw-r--r-- | test/buildtool/execution_api/execution_service/TARGETS | 22 | ||||
-rw-r--r-- | test/buildtool/execution_api/execution_service/cas_server.test.cpp | 74 |
3 files changed, 100 insertions, 1 deletions
diff --git a/test/buildtool/execution_api/TARGETS b/test/buildtool/execution_api/TARGETS index 893d12f1..5372a41e 100644 --- a/test/buildtool/execution_api/TARGETS +++ b/test/buildtool/execution_api/TARGETS @@ -12,6 +12,9 @@ { "type": "install" , "tainted": ["test"] , "dirs": - [[["./", "bazel", "TESTS"], "bazel"], [["./", "local", "TESTS"], "local"]] + [ [["./", "bazel", "TESTS"], "bazel"] + , [["./", "local", "TESTS"], "local"] + , [["./", "execution_service", "TESTS"], "execution_service"] + ] } } diff --git a/test/buildtool/execution_api/execution_service/TARGETS b/test/buildtool/execution_api/execution_service/TARGETS new file mode 100644 index 00000000..5fc60fa5 --- /dev/null +++ b/test/buildtool/execution_api/execution_service/TARGETS @@ -0,0 +1,22 @@ +{ "cas_server": + { "type": ["@", "rules", "CC/test", "test"] + , "name": ["cas_server"] + , "srcs": ["cas_server.test.cpp"] + , "private-deps": + [ ["", "catch-main"] + , ["@", "catch2", "", "catch2"] + , ["utils", "local_hermeticity"] + , [ "@" + , "src" + , "src/buildtool/execution_api/execution_service" + , "cas_server" + ] + , ["@", "src", "src/buildtool/file_system", "git_repo"] + , ["@", "src", "src/buildtool/file_system", "object_type"] + , ["@", "src", "src/buildtool/common", "common"] + , ["@", "gsl", "", "gsl"] + ] + , "stage": ["test", "buildtool", "execution_api", "execution_service"] + } +, "TESTS": {"type": "install", "tainted": ["test"], "deps": ["cas_server"]} +} diff --git a/test/buildtool/execution_api/execution_service/cas_server.test.cpp b/test/buildtool/execution_api/execution_service/cas_server.test.cpp new file mode 100644 index 00000000..5ddce950 --- /dev/null +++ b/test/buildtool/execution_api/execution_service/cas_server.test.cpp @@ -0,0 +1,74 @@ +// Copyright 2024 Huawei Cloud Computing Technology Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "catch2/catch_test_macros.hpp" +#include "gsl/gsl" +#include "src/buildtool/common/artifact_digest.hpp" +#include "src/buildtool/execution_api/execution_service/cas_server.hpp" +#include "src/buildtool/file_system/git_repo.hpp" +#include "src/buildtool/file_system/object_type.hpp" +#include "test/utils/hermeticity/local.hpp" + +namespace { +[[nodiscard]] auto Upload( + gsl::not_null<bazel_re::ContentAddressableStorage::Service*> const& + cas_server, + std::string const& instance_name, + bazel_re::Digest const& digest, + std::string const& content) noexcept -> grpc::Status { + auto request = bazel_re::BatchUpdateBlobsRequest{}; + request.set_instance_name(instance_name); + auto* req = request.add_requests(); + req->mutable_digest()->CopyFrom(digest); + req->set_data(content); + auto response = bazel_re::BatchUpdateBlobsResponse{}; + return cas_server->BatchUpdateBlobs(nullptr, &request, &response); +} +} // namespace + +TEST_CASE_METHOD(HermeticLocalTestFixture, + "CAS Service: upload incomplete tree", + "[execution_service]") { + auto cas_server = CASServiceImpl{}; + auto instance_name = std::string{"remote-execution"}; + + // Create an empty tree. + auto empty_entries = GitRepo::tree_entries_t{}; + auto empty_tree = GitRepo::CreateShallowTree(empty_entries); + REQUIRE(empty_tree); + auto empty_tree_digest = + ArtifactDigest::Create<ObjectType::Tree>(empty_tree->second); + + // Create a tree containing the empty tree. + auto entries = GitRepo::tree_entries_t{}; + entries[empty_tree->first].emplace_back("empty_tree", ObjectType::Tree); + auto tree = GitRepo::CreateShallowTree(entries); + REQUIRE(tree); + auto tree_digest = ArtifactDigest::Create<ObjectType::Tree>(tree->second); + + // Upload tree. The tree invariant is violated, thus, a negative answer is + // expected. + auto status = Upload(&cas_server, instance_name, tree_digest, tree->second); + CHECK(not status.ok()); + + // Upload empty tree. + status = Upload( + &cas_server, instance_name, empty_tree_digest, empty_tree->second); + CHECK(status.ok()); + + // Upload tree again. This time, the tree invariant is honored and a + // positive answer is expected. + status = Upload(&cas_server, instance_name, tree_digest, tree->second); + CHECK(status.ok()); +} |