From 013d83eed166049be110d47f00feb4c6af1315af Mon Sep 17 00:00:00 2001 From: Maksim Denisov Date: Thu, 29 Aug 2024 17:29:49 +0200 Subject: Use BazelDigestFactory to create bazel_re::Digest directly if needed ...bypassing ArtifactDigest functionality. --- test/buildtool/execution_api/bazel/TARGETS | 8 ++-- .../execution_api/bazel/bazel_cas_client.test.cpp | 6 +-- .../bazel/bazel_execution_client.test.cpp | 10 ++--- .../execution_api/bazel/bazel_network.test.cpp | 42 +++++++++--------- .../execution_api/bazel/bytestream_client.test.cpp | 51 +++++++++++----------- .../execution_api/execution_service/TARGETS | 1 + .../execution_service/cas_server.test.cpp | 5 ++- 7 files changed, 62 insertions(+), 61 deletions(-) (limited to 'test/buildtool') diff --git a/test/buildtool/execution_api/bazel/TARGETS b/test/buildtool/execution_api/bazel/TARGETS index 18a9e012..9d9aa5d8 100644 --- a/test/buildtool/execution_api/bazel/TARGETS +++ b/test/buildtool/execution_api/bazel/TARGETS @@ -8,7 +8,7 @@ , ["utils", "catch-main-remote-execution"] , ["utils", "test_auth_config"] , ["utils", "test_remote_config"] - , ["@", "src", "src/buildtool/common", "common"] + , ["@", "src", "src/buildtool/common", "bazel_digest_factory"] , ["@", "src", "src/buildtool/common/remote", "retry_config"] , ["@", "src", "src/buildtool/execution_api/bazel_msg", "bazel_msg"] , ["@", "src", "src/buildtool/execution_api/remote", "bazel_network"] @@ -28,7 +28,7 @@ , ["utils", "execution_bazel"] , ["utils", "test_auth_config"] , ["utils", "test_remote_config"] - , ["@", "src", "src/buildtool/common", "common"] + , ["@", "src", "src/buildtool/common", "bazel_digest_factory"] , ["@", "src", "src/buildtool/common/remote", "retry_config"] , ["@", "src", "src/buildtool/execution_api/remote", "bazel_network"] , ["@", "src", "src/buildtool/execution_api/remote", "config"] @@ -48,7 +48,7 @@ , ["utils", "execution_bazel"] , ["utils", "test_auth_config"] , ["utils", "test_remote_config"] - , ["@", "src", "src/buildtool/common", "common"] + , ["@", "src", "src/buildtool/common", "bazel_digest_factory"] , ["@", "src", "src/buildtool/execution_api/bazel_msg", "bazel_msg"] , ["@", "src", "src/buildtool/execution_api/remote", "bazel_network"] , ["@", "src", "src/buildtool/execution_api/remote", "config"] @@ -68,7 +68,7 @@ , ["utils", "execution_bazel"] , ["utils", "test_auth_config"] , ["utils", "test_remote_config"] - , ["@", "src", "src/buildtool/common", "common"] + , ["@", "src", "src/buildtool/common", "bazel_digest_factory"] , ["@", "src", "src/buildtool/common/remote", "retry_config"] , ["@", "src", "src/buildtool/compatibility", "compatibility"] , ["@", "src", "src/buildtool/execution_api/bazel_msg", "bazel_msg"] diff --git a/test/buildtool/execution_api/bazel/bazel_cas_client.test.cpp b/test/buildtool/execution_api/bazel/bazel_cas_client.test.cpp index bd005497..e4772f7d 100644 --- a/test/buildtool/execution_api/bazel/bazel_cas_client.test.cpp +++ b/test/buildtool/execution_api/bazel/bazel_cas_client.test.cpp @@ -20,7 +20,7 @@ #include "catch2/catch_test_macros.hpp" #include "gsl/gsl" -#include "src/buildtool/common/artifact_digest.hpp" +#include "src/buildtool/common/bazel_digest_factory.hpp" #include "src/buildtool/common/remote/retry_config.hpp" #include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/execution_api/bazel_msg/bazel_blob_container.hpp" @@ -52,8 +52,8 @@ TEST_CASE("Bazel internals: CAS Client", "[execution_api]") { HashFunction const hash_function{Compatibility::IsCompatible() ? HashFunction::Type::PlainSHA256 : HashFunction::Type::GitSHA1}; - auto digest = - ArtifactDigest::Create(hash_function, content); + auto digest = BazelDigestFactory::HashDataAs( + hash_function, content); // Valid blob BazelBlob blob{digest, content, /*is_exec=*/false}; diff --git a/test/buildtool/execution_api/bazel/bazel_execution_client.test.cpp b/test/buildtool/execution_api/bazel/bazel_execution_client.test.cpp index 093c4eb1..c354316c 100644 --- a/test/buildtool/execution_api/bazel/bazel_execution_client.test.cpp +++ b/test/buildtool/execution_api/bazel/bazel_execution_client.test.cpp @@ -17,7 +17,7 @@ #include #include "catch2/catch_test_macros.hpp" -#include "src/buildtool/common/artifact_digest.hpp" +#include "src/buildtool/common/bazel_digest_factory.hpp" #include "src/buildtool/common/remote/retry_config.hpp" #include "src/buildtool/compatibility/compatibility.hpp" #include "src/buildtool/crypto/hash_function.hpp" @@ -35,8 +35,8 @@ TEST_CASE("Bazel internals: Execution Client", "[execution_api]") { ? HashFunction::Type::PlainSHA256 : HashFunction::Type::GitSHA1}; - auto test_digest = static_cast( - ArtifactDigest::Create(hash_function, content)); + auto test_digest = BazelDigestFactory::HashDataAs( + hash_function, content); auto auth_config = TestAuthConfig::ReadFromEnvironment(); REQUIRE(auth_config); @@ -119,8 +119,8 @@ TEST_CASE("Bazel internals: Execution Client using env variables", ? HashFunction::Type::PlainSHA256 : HashFunction::Type::GitSHA1}; - auto test_digest = static_cast( - ArtifactDigest::Create(hash_function, content)); + auto test_digest = BazelDigestFactory::HashDataAs( + hash_function, content); auto auth_config = TestAuthConfig::ReadFromEnvironment(); REQUIRE(auth_config); diff --git a/test/buildtool/execution_api/bazel/bazel_network.test.cpp b/test/buildtool/execution_api/bazel/bazel_network.test.cpp index edc35ea7..01c5aea9 100644 --- a/test/buildtool/execution_api/bazel/bazel_network.test.cpp +++ b/test/buildtool/execution_api/bazel/bazel_network.test.cpp @@ -21,7 +21,7 @@ #include "catch2/catch_test_macros.hpp" #include "src/buildtool/auth/authentication.hpp" -#include "src/buildtool/common/artifact_digest.hpp" +#include "src/buildtool/common/bazel_digest_factory.hpp" #include "src/buildtool/common/remote/retry_config.hpp" #include "src/buildtool/compatibility/compatibility.hpp" #include "src/buildtool/crypto/hash_function.hpp" @@ -62,18 +62,18 @@ TEST_CASE("Bazel network: write/read blobs", "[execution_api]") { std::string content_bar("bar"); std::string content_baz(kLargeSize, 'x'); // single larger blob - BazelBlob foo{ - ArtifactDigest::Create(hash_function, content_foo), - content_foo, - /*is_exec=*/false}; - BazelBlob bar{ - ArtifactDigest::Create(hash_function, content_bar), - content_bar, - /*is_exec=*/false}; - BazelBlob baz{ - ArtifactDigest::Create(hash_function, content_baz), - content_baz, - /*is_exec=*/false}; + BazelBlob foo{BazelDigestFactory::HashDataAs( + hash_function, content_foo), + content_foo, + /*is_exec=*/false}; + BazelBlob bar{BazelDigestFactory::HashDataAs( + hash_function, content_bar), + content_bar, + /*is_exec=*/false}; + BazelBlob baz{BazelDigestFactory::HashDataAs( + hash_function, content_baz), + content_baz, + /*is_exec=*/false}; // Search blobs via digest REQUIRE(network.UploadBlobs(BazelBlobContainer{{foo, bar, baz}})); @@ -128,14 +128,14 @@ TEST_CASE("Bazel network: read blobs with unknown size", "[execution_api]") { std::string content_foo("foo"); std::string content_bar(kLargeSize, 'x'); // single larger blob - BazelBlob foo{ - ArtifactDigest::Create(hash_function, content_foo), - content_foo, - /*is_exec=*/false}; - BazelBlob bar{ - ArtifactDigest::Create(hash_function, content_bar), - content_bar, - /*is_exec=*/false}; + BazelBlob foo{BazelDigestFactory::HashDataAs( + hash_function, content_foo), + content_foo, + /*is_exec=*/false}; + BazelBlob bar{BazelDigestFactory::HashDataAs( + hash_function, content_bar), + content_bar, + /*is_exec=*/false}; // Upload blobs REQUIRE(network.UploadBlobs(BazelBlobContainer{{foo, bar}})); diff --git a/test/buildtool/execution_api/bazel/bytestream_client.test.cpp b/test/buildtool/execution_api/bazel/bytestream_client.test.cpp index 10fe0c83..731073e5 100644 --- a/test/buildtool/execution_api/bazel/bytestream_client.test.cpp +++ b/test/buildtool/execution_api/bazel/bytestream_client.test.cpp @@ -20,7 +20,7 @@ #include "catch2/catch_test_macros.hpp" #include "src/buildtool/auth/authentication.hpp" -#include "src/buildtool/common/artifact_digest.hpp" +#include "src/buildtool/common/bazel_digest_factory.hpp" #include "src/buildtool/compatibility/compatibility.hpp" #include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/execution_api/bazel_msg/bazel_blob_container.hpp" @@ -54,8 +54,8 @@ TEST_CASE("ByteStream Client: Transfer single blob", "[execution_api]") { std::string content("foobar"); // digest of "foobar" - auto digest = static_cast( - ArtifactDigest::Create(hash_function, content)); + auto digest = BazelDigestFactory::HashDataAs( + hash_function, content); CHECK(stream.Write(fmt::format("{}/uploads/{}/blobs/{}/{}", instance_name, @@ -80,9 +80,8 @@ TEST_CASE("ByteStream Client: Transfer single blob", "[execution_api]") { std::string other_content("This is a differnt string"); // Valid digest, but for a different string - auto digest = static_cast( - ArtifactDigest::Create(hash_function, - other_content)); + auto digest = BazelDigestFactory::HashDataAs( + hash_function, other_content); CHECK(not stream.Write(fmt::format("{}/uploads/{}/blobs/{}/{}", instance_name, @@ -101,8 +100,8 @@ TEST_CASE("ByteStream Client: Transfer single blob", "[execution_api]") { } // digest of "instance_nameinstance_nameinstance_..." - auto digest = static_cast( - ArtifactDigest::Create(hash_function, content)); + auto digest = BazelDigestFactory::HashDataAs( + hash_function, content); CHECK(stream.Write(fmt::format("{}/uploads/{}/blobs/{}/{}", instance_name, @@ -160,18 +159,18 @@ TEST_CASE("ByteStream Client: Transfer multiple blobs", "[execution_api]") { SECTION("Upload small blobs") { std::string instance_name{"remote-execution"}; - BazelBlob foo{ - ArtifactDigest::Create(hash_function, "foo"), - "foo", - /*is_exec=*/false}; - BazelBlob bar{ - ArtifactDigest::Create(hash_function, "bar"), - "bar", - /*is_exec=*/false}; - BazelBlob baz{ - ArtifactDigest::Create(hash_function, "baz"), - "baz", - /*is_exec=*/false}; + BazelBlob foo{BazelDigestFactory::HashDataAs( + hash_function, "foo"), + "foo", + /*is_exec=*/false}; + BazelBlob bar{BazelDigestFactory::HashDataAs( + hash_function, "bar"), + "bar", + /*is_exec=*/false}; + BazelBlob baz{BazelDigestFactory::HashDataAs( + hash_function, "baz"), + "baz", + /*is_exec=*/false}; CHECK(stream.WriteMany( {foo, bar, baz}, @@ -216,16 +215,16 @@ TEST_CASE("ByteStream Client: Transfer multiple blobs", "[execution_api]") { content_baz[i] = instance_name[(i + 2) % instance_name.size()]; } - BazelBlob foo{ArtifactDigest::Create(hash_function, - content_foo), + BazelBlob foo{BazelDigestFactory::HashDataAs( + hash_function, content_foo), content_foo, /*is_exec=*/false}; - BazelBlob bar{ArtifactDigest::Create(hash_function, - content_bar), + BazelBlob bar{BazelDigestFactory::HashDataAs( + hash_function, content_bar), content_bar, /*is_exec=*/false}; - BazelBlob baz{ArtifactDigest::Create(hash_function, - content_baz), + BazelBlob baz{BazelDigestFactory::HashDataAs( + hash_function, content_baz), content_baz, /*is_exec=*/false}; diff --git a/test/buildtool/execution_api/execution_service/TARGETS b/test/buildtool/execution_api/execution_service/TARGETS index 0e32c4ad..a2c1e9dd 100644 --- a/test/buildtool/execution_api/execution_service/TARGETS +++ b/test/buildtool/execution_api/execution_service/TARGETS @@ -16,6 +16,7 @@ , ["@", "src", "src/buildtool/file_system", "git_repo"] , ["@", "src", "src/buildtool/file_system", "object_type"] , ["@", "src", "src/buildtool/common", "common"] + , ["@", "src", "src/buildtool/common", "bazel_digest_factory"] , ["@", "src", "src/buildtool/storage", "config"] , ["@", "src", "src/buildtool/storage", "storage"] , ["@", "gsl", "", "gsl"] diff --git a/test/buildtool/execution_api/execution_service/cas_server.test.cpp b/test/buildtool/execution_api/execution_service/cas_server.test.cpp index 4bc90546..ca88b17b 100644 --- a/test/buildtool/execution_api/execution_service/cas_server.test.cpp +++ b/test/buildtool/execution_api/execution_service/cas_server.test.cpp @@ -19,6 +19,7 @@ #include "catch2/catch_test_macros.hpp" #include "gsl/gsl" #include "src/buildtool/common/artifact_digest.hpp" +#include "src/buildtool/common/bazel_digest_factory.hpp" #include "src/buildtool/execution_api/local/config.hpp" #include "src/buildtool/execution_api/local/context.hpp" #include "src/buildtool/file_system/git_repo.hpp" @@ -66,7 +67,7 @@ TEST_CASE("CAS Service: upload incomplete tree", "[execution_service]") { auto empty_entries = GitRepo::tree_entries_t{}; auto empty_tree = GitRepo::CreateShallowTree(empty_entries); REQUIRE(empty_tree); - auto empty_tree_digest = ArtifactDigest::Create( + auto empty_tree_digest = BazelDigestFactory::HashDataAs( storage_config.Get().hash_function, empty_tree->second); // Create a tree containing the empty tree. @@ -74,7 +75,7 @@ TEST_CASE("CAS Service: upload incomplete tree", "[execution_service]") { entries[empty_tree->first].emplace_back("empty_tree", ObjectType::Tree); auto tree = GitRepo::CreateShallowTree(entries); REQUIRE(tree); - auto tree_digest = ArtifactDigest::Create( + auto tree_digest = BazelDigestFactory::HashDataAs( storage_config.Get().hash_function, tree->second); // Upload tree. The tree invariant is violated, thus, a negative answer is -- cgit v1.2.3