diff options
author | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2024-07-12 16:09:28 +0200 |
---|---|---|
committer | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2024-07-16 17:51:12 +0200 |
commit | 62d204ff4cc94c12c1635f189255710901682825 (patch) | |
tree | 0c5cdc5faf98d28ddf74721280756804a6decf83 /test | |
parent | de3ef374983d987d8ffd8e8516a4877fe68b3e4e (diff) | |
download | justbuild-62d204ff4cc94c12c1635f189255710901682825.tar.gz |
Remove the RemoteExecutionConfig singleton
...and replace it with passed instances created early via a builder
pattern.
Tests are also updated accordingly.
Diffstat (limited to 'test')
18 files changed, 485 insertions, 241 deletions
diff --git a/test/buildtool/build_engine/target_map/target_map.test.cpp b/test/buildtool/build_engine/target_map/target_map.test.cpp index 5ec27e97..4d7cef75 100644 --- a/test/buildtool/build_engine/target_map/target_map.test.cpp +++ b/test/buildtool/build_engine/target_map/target_map.test.cpp @@ -107,13 +107,14 @@ TEST_CASE("simple targets", "[target_map]") { REQUIRE(serve_config); LocalExecutionConfig local_exec_config{}; + RemoteExecutionConfig remote_exec_config{}; Auth auth{}; ApiBundle const apis{&storage_config.Get(), &storage, &local_exec_config, /*repo_config=*/nullptr, &auth, - &RemoteExecutionConfig::Instance()}; + &remote_exec_config}; auto serve = ServeApi::Create(*serve_config, &storage, &apis); AnalyseContext ctx{.repo_config = &repo_config, .storage = &storage, @@ -558,13 +559,14 @@ TEST_CASE("configuration deduplication", "[target_map]") { REQUIRE(serve_config); LocalExecutionConfig local_exec_config{}; + RemoteExecutionConfig remote_exec_config{}; Auth auth{}; ApiBundle const apis{&storage_config.Get(), &storage, &local_exec_config, /*repo_config=*/nullptr, &auth, - &RemoteExecutionConfig::Instance()}; + &remote_exec_config}; auto serve = ServeApi::Create(*serve_config, &storage, &apis); AnalyseContext ctx{.repo_config = &repo_config, .storage = &storage, @@ -654,13 +656,14 @@ TEST_CASE("generator functions in string arguments", "[target_map]") { REQUIRE(serve_config); LocalExecutionConfig local_exec_config{}; + RemoteExecutionConfig remote_exec_config{}; Auth auth{}; ApiBundle const apis{&storage_config.Get(), &storage, &local_exec_config, /*repo_config=*/nullptr, &auth, - &RemoteExecutionConfig::Instance()}; + &remote_exec_config}; auto serve = ServeApi::Create(*serve_config, &storage, &apis); AnalyseContext ctx{.repo_config = &repo_config, .storage = &storage, @@ -762,13 +765,14 @@ TEST_CASE("built-in rules", "[target_map]") { REQUIRE(serve_config); LocalExecutionConfig local_exec_config{}; + RemoteExecutionConfig remote_exec_config{}; Auth auth{}; ApiBundle const apis{&storage_config.Get(), &storage, &local_exec_config, /*repo_config=*/nullptr, &auth, - &RemoteExecutionConfig::Instance()}; + &remote_exec_config}; auto serve = ServeApi::Create(*serve_config, &storage, &apis); AnalyseContext ctx{.repo_config = &repo_config, .storage = &storage, @@ -980,13 +984,14 @@ TEST_CASE("target reference", "[target_map]") { REQUIRE(serve_config); LocalExecutionConfig local_exec_config{}; + RemoteExecutionConfig remote_exec_config{}; Auth auth{}; ApiBundle const apis{&storage_config.Get(), &storage, &local_exec_config, /*repo_config=*/nullptr, &auth, - &RemoteExecutionConfig::Instance()}; + &remote_exec_config}; auto serve = ServeApi::Create(*serve_config, &storage, &apis); AnalyseContext ctx{.repo_config = &repo_config, .storage = &storage, @@ -1131,13 +1136,14 @@ TEST_CASE("trees", "[target_map]") { REQUIRE(serve_config); LocalExecutionConfig local_exec_config{}; + RemoteExecutionConfig remote_exec_config{}; Auth auth{}; ApiBundle const apis{&storage_config.Get(), &storage, &local_exec_config, /*repo_config=*/nullptr, &auth, - &RemoteExecutionConfig::Instance()}; + &remote_exec_config}; auto serve = ServeApi::Create(*serve_config, &storage, &apis); AnalyseContext ctx{.repo_config = &repo_config, .storage = &storage, @@ -1246,13 +1252,14 @@ TEST_CASE("RESULT error reporting", "[target_map]") { REQUIRE(serve_config); LocalExecutionConfig local_exec_config{}; + RemoteExecutionConfig remote_exec_config{}; Auth auth{}; ApiBundle const apis{&storage_config.Get(), &storage, &local_exec_config, /*repo_config=*/nullptr, &auth, - &RemoteExecutionConfig::Instance()}; + &remote_exec_config}; auto serve = ServeApi::Create(*serve_config, &storage, &apis); AnalyseContext ctx{.repo_config = &repo_config, .storage = &storage, @@ -1420,13 +1427,14 @@ TEST_CASE("wrong arguments", "[target_map]") { REQUIRE(serve_config); LocalExecutionConfig local_exec_config{}; + RemoteExecutionConfig remote_exec_config{}; Auth auth{}; ApiBundle const apis{&storage_config.Get(), &storage, &local_exec_config, /*repo_config=*/nullptr, &auth, - &RemoteExecutionConfig::Instance()}; + &remote_exec_config}; auto serve = ServeApi::Create(*serve_config, &storage, &apis); AnalyseContext ctx{.repo_config = &repo_config, .storage = &storage, diff --git a/test/buildtool/execution_api/bazel/TARGETS b/test/buildtool/execution_api/bazel/TARGETS index f9caa7ee..8ea89e15 100644 --- a/test/buildtool/execution_api/bazel/TARGETS +++ b/test/buildtool/execution_api/bazel/TARGETS @@ -7,6 +7,7 @@ , ["@", "gsl", "", "gsl"] , ["utils", "catch-main-remote-execution"] , ["utils", "test_auth_config"] + , ["utils", "test_remote_config"] , ["@", "src", "src/buildtool/common", "common"] , ["@", "src", "src/buildtool/execution_api/bazel_msg", "bazel_msg"] , ["@", "src", "src/buildtool/execution_api/remote", "bazel_network"] @@ -24,6 +25,7 @@ , ["utils", "catch-main-remote-execution"] , ["utils", "execution_bazel"] , ["utils", "test_auth_config"] + , ["utils", "test_remote_config"] , ["@", "src", "src/buildtool/common", "common"] , ["@", "src", "src/buildtool/execution_api/remote", "bazel_network"] , ["@", "src", "src/buildtool/execution_api/remote", "config"] @@ -40,6 +42,7 @@ , ["utils", "catch-main-remote-execution"] , ["utils", "execution_bazel"] , ["utils", "test_auth_config"] + , ["utils", "test_remote_config"] , ["@", "src", "src/buildtool/common", "common"] , ["@", "src", "src/buildtool/execution_api/bazel_msg", "bazel_msg"] , ["@", "src", "src/buildtool/execution_api/remote", "bazel_network"] @@ -57,6 +60,7 @@ , ["utils", "catch-main-remote-execution"] , ["utils", "execution_bazel"] , ["utils", "test_auth_config"] + , ["utils", "test_remote_config"] , ["@", "src", "src/buildtool/common", "common"] , ["@", "src", "src/buildtool/compatibility", "compatibility"] , ["@", "src", "src/buildtool/execution_api/bazel_msg", "bazel_msg"] @@ -93,6 +97,7 @@ [ ["@", "catch2", "", "catch2"] , ["utils", "catch-main-remote-execution"] , ["utils", "test_auth_config"] + , ["utils", "test_remote_config"] , ["@", "src", "src/buildtool/execution_api/remote", "bazel"] , ["buildtool/execution_api/common", "api_test"] ] diff --git a/test/buildtool/execution_api/bazel/bazel_api.test.cpp b/test/buildtool/execution_api/bazel/bazel_api.test.cpp index 8c2d6633..9b9e6def 100644 --- a/test/buildtool/execution_api/bazel/bazel_api.test.cpp +++ b/test/buildtool/execution_api/bazel/bazel_api.test.cpp @@ -20,59 +20,75 @@ #include "src/buildtool/execution_api/remote/config.hpp" #include "test/buildtool/execution_api/common/api_test.hpp" #include "test/utils/remote_execution/test_auth_config.hpp" +#include "test/utils/remote_execution/test_remote_config.hpp" namespace { auto const kApiFactory = []() { - static auto const& server = RemoteExecutionConfig::RemoteAddress(); + auto remote_config = TestRemoteConfig::ReadFromEnvironment(); + REQUIRE(remote_config); + REQUIRE(remote_config->remote_address); auto auth_config = TestAuthConfig::ReadFromEnvironment(); REQUIRE(auth_config); - return IExecutionApi::Ptr{new BazelApi{ - "remote-execution", server->host, server->port, &*auth_config, {}}}; + return IExecutionApi::Ptr{new BazelApi{"remote-execution", + remote_config->remote_address->host, + remote_config->remote_address->port, + &*auth_config, + {}}}; }; } // namespace TEST_CASE("BazelAPI: No input, no output", "[execution_api]") { - TestNoInputNoOutput(kApiFactory, - RemoteExecutionConfig::PlatformProperties()); + auto remote_config = TestRemoteConfig::ReadFromEnvironment(); + REQUIRE(remote_config); + TestNoInputNoOutput(kApiFactory, remote_config->platform_properties); } TEST_CASE("BazelAPI: No input, create output", "[execution_api]") { - TestNoInputCreateOutput(kApiFactory, - RemoteExecutionConfig::PlatformProperties()); + auto remote_config = TestRemoteConfig::ReadFromEnvironment(); + REQUIRE(remote_config); + TestNoInputCreateOutput(kApiFactory, remote_config->platform_properties); } TEST_CASE("BazelAPI: One input copied to output", "[execution_api]") { - TestOneInputCopiedToOutput(kApiFactory, - RemoteExecutionConfig::PlatformProperties()); + auto remote_config = TestRemoteConfig::ReadFromEnvironment(); + REQUIRE(remote_config); + TestOneInputCopiedToOutput(kApiFactory, remote_config->platform_properties); } TEST_CASE("BazelAPI: Non-zero exit code, create output", "[execution_api]") { - TestNonZeroExitCodeCreateOutput( - kApiFactory, RemoteExecutionConfig::PlatformProperties()); + auto remote_config = TestRemoteConfig::ReadFromEnvironment(); + REQUIRE(remote_config); + TestNonZeroExitCodeCreateOutput(kApiFactory, + remote_config->platform_properties); } TEST_CASE("BazelAPI: Retrieve two identical trees to path", "[execution_api]") { + auto remote_config = TestRemoteConfig::ReadFromEnvironment(); + REQUIRE(remote_config); TestRetrieveTwoIdenticalTreesToPath( - kApiFactory, RemoteExecutionConfig::PlatformProperties(), "two_trees"); + kApiFactory, remote_config->platform_properties, "two_trees"); } TEST_CASE("BazelAPI: Retrieve file and symlink with same content to path", "[execution_api]") { + auto remote_config = TestRemoteConfig::ReadFromEnvironment(); + REQUIRE(remote_config); TestRetrieveFileAndSymlinkWithSameContentToPath( - kApiFactory, - RemoteExecutionConfig::PlatformProperties(), - "file_and_symlink"); + kApiFactory, remote_config->platform_properties, "file_and_symlink"); } TEST_CASE("BazelAPI: Retrieve mixed blobs and trees", "[execution_api]") { - TestRetrieveMixedBlobsAndTrees(kApiFactory, - RemoteExecutionConfig::PlatformProperties(), - "blobs_and_trees"); + auto remote_config = TestRemoteConfig::ReadFromEnvironment(); + REQUIRE(remote_config); + TestRetrieveMixedBlobsAndTrees( + kApiFactory, remote_config->platform_properties, "blobs_and_trees"); } TEST_CASE("BazelAPI: Create directory prior to execution", "[execution_api]") { + auto remote_config = TestRemoteConfig::ReadFromEnvironment(); + REQUIRE(remote_config); TestCreateDirPriorToExecution(kApiFactory, - RemoteExecutionConfig::PlatformProperties()); + remote_config->platform_properties); } 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 4cd5e13b..68293fd2 100644 --- a/test/buildtool/execution_api/bazel/bazel_cas_client.test.cpp +++ b/test/buildtool/execution_api/bazel/bazel_cas_client.test.cpp @@ -25,10 +25,9 @@ #include "src/buildtool/execution_api/remote/config.hpp" #include "src/buildtool/file_system/object_type.hpp" #include "test/utils/remote_execution/test_auth_config.hpp" +#include "test/utils/remote_execution/test_remote_config.hpp" TEST_CASE("Bazel internals: CAS Client", "[execution_api]") { - auto const& info = RemoteExecutionConfig::RemoteAddress(); - std::string instance_name{"remote-execution"}; std::string content("test"); @@ -36,7 +35,12 @@ TEST_CASE("Bazel internals: CAS Client", "[execution_api]") { REQUIRE(auth_config); // Create CAS client - BazelCasClient cas_client(info->host, info->port, &*auth_config); + auto remote_config = TestRemoteConfig::ReadFromEnvironment(); + REQUIRE(remote_config); + REQUIRE(remote_config->remote_address); + BazelCasClient cas_client(remote_config->remote_address->host, + remote_config->remote_address->port, + &*auth_config); SECTION("Valid digest and blob") { // digest of "test" 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 c1f70ecc..9759a820 100755 --- a/test/buildtool/execution_api/bazel/bazel_execution_client.test.cpp +++ b/test/buildtool/execution_api/bazel/bazel_execution_client.test.cpp @@ -21,10 +21,9 @@ #include "src/buildtool/file_system/object_type.hpp" #include "test/utils/remote_execution/bazel_action_creator.hpp" #include "test/utils/remote_execution/test_auth_config.hpp" +#include "test/utils/remote_execution/test_remote_config.hpp" TEST_CASE("Bazel internals: Execution Client", "[execution_api]") { - auto const& info = RemoteExecutionConfig::RemoteAddress(); - std::string instance_name{"remote-execution"}; std::string content("test"); auto test_digest = static_cast<bazel_re::Digest>( @@ -33,8 +32,13 @@ TEST_CASE("Bazel internals: Execution Client", "[execution_api]") { auto auth_config = TestAuthConfig::ReadFromEnvironment(); REQUIRE(auth_config); - BazelExecutionClient execution_client( - info->host, info->port, &*auth_config); + auto remote_config = TestRemoteConfig::ReadFromEnvironment(); + REQUIRE(remote_config); + REQUIRE(remote_config->remote_address); + + BazelExecutionClient execution_client(remote_config->remote_address->host, + remote_config->remote_address->port, + &*auth_config); ExecutionConfiguration config; config.skip_cache_lookup = false; @@ -44,7 +48,7 @@ TEST_CASE("Bazel internals: Execution Client", "[execution_api]") { CreateAction(instance_name, {"echo", "-n", content}, {}, - RemoteExecutionConfig::PlatformProperties()); + remote_config->platform_properties); REQUIRE(action_immediate); auto response = execution_client.Execute( @@ -63,7 +67,7 @@ TEST_CASE("Bazel internals: Execution Client", "[execution_api]") { CreateAction(instance_name, {"sh", "-c", "sleep 1s; echo -n test"}, {}, - RemoteExecutionConfig::PlatformProperties()); + remote_config->platform_properties); SECTION("Blocking, immediately obtain result") { auto response = execution_client.Execute( @@ -95,8 +99,6 @@ TEST_CASE("Bazel internals: Execution Client", "[execution_api]") { TEST_CASE("Bazel internals: Execution Client using env variables", "[execution_api]") { - auto const& info = RemoteExecutionConfig::RemoteAddress(); - std::string instance_name{"remote-execution"}; std::string content("contents of env variable"); auto test_digest = static_cast<bazel_re::Digest>( @@ -105,8 +107,13 @@ TEST_CASE("Bazel internals: Execution Client using env variables", auto auth_config = TestAuthConfig::ReadFromEnvironment(); REQUIRE(auth_config); - BazelExecutionClient execution_client( - info->host, info->port, &*auth_config); + auto remote_config = TestRemoteConfig::ReadFromEnvironment(); + REQUIRE(remote_config); + REQUIRE(remote_config->remote_address); + + BazelExecutionClient execution_client(remote_config->remote_address->host, + remote_config->remote_address->port, + &*auth_config); ExecutionConfiguration config; config.skip_cache_lookup = false; @@ -114,7 +121,7 @@ TEST_CASE("Bazel internals: Execution Client using env variables", CreateAction(instance_name, {"/bin/sh", "-c", "set -e\necho -n ${MYTESTVAR}"}, {{"MYTESTVAR", content}}, - RemoteExecutionConfig::PlatformProperties()); + remote_config->platform_properties); REQUIRE(action); auto response = diff --git a/test/buildtool/execution_api/bazel/bazel_network.test.cpp b/test/buildtool/execution_api/bazel/bazel_network.test.cpp index 443ca30d..59fd027f 100644 --- a/test/buildtool/execution_api/bazel/bazel_network.test.cpp +++ b/test/buildtool/execution_api/bazel/bazel_network.test.cpp @@ -27,16 +27,25 @@ #include "src/buildtool/execution_api/remote/config.hpp" #include "src/buildtool/file_system/object_type.hpp" #include "test/utils/remote_execution/test_auth_config.hpp" +#include "test/utils/remote_execution/test_remote_config.hpp" constexpr std::size_t kLargeSize = GRPC_DEFAULT_MAX_RECV_MESSAGE_LENGTH + 1; TEST_CASE("Bazel network: write/read blobs", "[execution_api]") { - auto const& info = RemoteExecutionConfig::RemoteAddress(); std::string instance_name{"remote-execution"}; + auto auth_config = TestAuthConfig::ReadFromEnvironment(); REQUIRE(auth_config); - auto network = - BazelNetwork{instance_name, info->host, info->port, &*auth_config, {}}; + + auto remote_config = TestRemoteConfig::ReadFromEnvironment(); + REQUIRE(remote_config); + REQUIRE(remote_config->remote_address); + + auto network = BazelNetwork{instance_name, + remote_config->remote_address->host, + remote_config->remote_address->port, + &*auth_config, + {}}; std::string content_foo("foo"); std::string content_bar("bar"); @@ -79,12 +88,20 @@ TEST_CASE("Bazel network: read blobs with unknown size", "[execution_api]") { return; } - auto const& info = RemoteExecutionConfig::RemoteAddress(); std::string instance_name{"remote-execution"}; + auto auth_config = TestAuthConfig::ReadFromEnvironment(); REQUIRE(auth_config); - auto network = - BazelNetwork{instance_name, info->host, info->port, &*auth_config, {}}; + + auto remote_config = TestRemoteConfig::ReadFromEnvironment(); + REQUIRE(remote_config); + REQUIRE(remote_config->remote_address); + + auto network = BazelNetwork{instance_name, + remote_config->remote_address->host, + remote_config->remote_address->port, + &*auth_config, + {}}; std::string content_foo("foo"); std::string content_bar(kLargeSize, 'x'); // single larger blob diff --git a/test/buildtool/execution_api/bazel/bytestream_client.test.cpp b/test/buildtool/execution_api/bazel/bytestream_client.test.cpp index 3b936068..293d2c45 100644 --- a/test/buildtool/execution_api/bazel/bytestream_client.test.cpp +++ b/test/buildtool/execution_api/bazel/bytestream_client.test.cpp @@ -25,14 +25,21 @@ #include "src/buildtool/execution_api/remote/config.hpp" #include "src/buildtool/file_system/object_type.hpp" #include "test/utils/remote_execution/test_auth_config.hpp" +#include "test/utils/remote_execution/test_remote_config.hpp" constexpr std::size_t kLargeSize = GRPC_DEFAULT_MAX_RECV_MESSAGE_LENGTH + 1; TEST_CASE("ByteStream Client: Transfer single blob", "[execution_api]") { - auto const& info = RemoteExecutionConfig::RemoteAddress(); auto auth_config = TestAuthConfig::ReadFromEnvironment(); REQUIRE(auth_config); - auto stream = ByteStreamClient{info->host, info->port, &*auth_config}; + + auto remote_config = TestRemoteConfig::ReadFromEnvironment(); + REQUIRE(remote_config); + REQUIRE(remote_config->remote_address); + + auto stream = ByteStreamClient{remote_config->remote_address->host, + remote_config->remote_address->port, + &*auth_config}; auto uuid = CreateUUIDVersion4(*CreateProcessUniqueId()); SECTION("Upload small blob") { @@ -109,10 +116,16 @@ TEST_CASE("ByteStream Client: Transfer single blob", "[execution_api]") { } TEST_CASE("ByteStream Client: Transfer multiple blobs", "[execution_api]") { - auto const& info = RemoteExecutionConfig::RemoteAddress(); auto auth_config = TestAuthConfig::ReadFromEnvironment(); REQUIRE(auth_config); - auto stream = ByteStreamClient{info->host, info->port, &*auth_config}; + + auto remote_config = TestRemoteConfig::ReadFromEnvironment(); + REQUIRE(remote_config); + REQUIRE(remote_config->remote_address); + + auto stream = ByteStreamClient{remote_config->remote_address->host, + remote_config->remote_address->port, + &*auth_config}; auto uuid = CreateUUIDVersion4(*CreateProcessUniqueId()); SECTION("Upload small blobs") { diff --git a/test/buildtool/execution_engine/executor/TARGETS b/test/buildtool/execution_engine/executor/TARGETS index 26b4e9a8..ab5c197a 100644 --- a/test/buildtool/execution_engine/executor/TARGETS +++ b/test/buildtool/execution_engine/executor/TARGETS @@ -14,6 +14,7 @@ , ["@", "src", "src/buildtool/progress_reporting", "progress"] , ["@", "catch2", "", "catch2"] , ["@", "gsl", "", "gsl"] + , ["utils", "test_remote_config"] ] , "stage": ["test", "buildtool", "execution_engine", "executor"] } @@ -74,6 +75,7 @@ , ["@", "src", "src/buildtool/progress_reporting", "progress"] , ["utils", "catch-main-remote-execution"] , ["utils", "test_auth_config"] + , ["utils", "test_remote_config"] , ["@", "catch2", "", "catch2"] ] , "stage": ["test", "buildtool", "execution_engine", "executor"] diff --git a/test/buildtool/execution_engine/executor/executor_api.test.hpp b/test/buildtool/execution_engine/executor/executor_api.test.hpp index a57c6f36..6689a87c 100644 --- a/test/buildtool/execution_engine/executor/executor_api.test.hpp +++ b/test/buildtool/execution_engine/executor/executor_api.test.hpp @@ -34,6 +34,7 @@ #include "src/buildtool/execution_engine/executor/executor.hpp" #include "src/buildtool/file_system/file_system_manager.hpp" #include "src/buildtool/progress_reporting/progress.hpp" +#include "test/utils/remote_execution/test_remote_config.hpp" using ApiFactory = std::function<IExecutionApi::Ptr()>; @@ -124,12 +125,15 @@ static inline void RunHelloWorldCompilation( CHECK(g.AddAction(make_hello_desc)); CHECK(g.ArtifactNodeWithId(exec_id)->HasBuilderAction()); + auto remote_config = TestRemoteConfig::ReadFromEnvironment(); + REQUIRE(remote_config); + auto api = factory(); Executor runner{repo_config, api.get(), api.get(), - RemoteExecutionConfig::PlatformProperties(), - RemoteExecutionConfig::DispatchList(), + remote_config->platform_properties, + remote_config->dispatch, auth, stats, progress}; @@ -247,12 +251,15 @@ static inline void RunGreeterCompilation( DependencyGraph g; CHECK(g.Add({compile_greet_desc, make_lib_desc, make_exe_desc})); + auto remote_config = TestRemoteConfig::ReadFromEnvironment(); + REQUIRE(remote_config); + auto api = factory(); Executor runner{repo_config, api.get(), api.get(), - RemoteExecutionConfig::PlatformProperties(), - RemoteExecutionConfig::DispatchList(), + remote_config->platform_properties, + remote_config->dispatch, auth, stats, progress}; @@ -411,11 +418,14 @@ static inline void TestUploadAndDownloadTrees( auto foo_id = g.AddArtifact(foo_desc); auto bar_id = g.AddArtifact(bar_desc); + auto remote_config = TestRemoteConfig::ReadFromEnvironment(); + REQUIRE(remote_config); + Executor runner{repo_config, api.get(), api.get(), - RemoteExecutionConfig::PlatformProperties(), - RemoteExecutionConfig::DispatchList(), + remote_config->platform_properties, + remote_config->dispatch, auth, stats, progress}; @@ -560,6 +570,9 @@ static inline void TestRetrieveOutputDirectories( {}}; }; + auto remote_config = TestRemoteConfig::ReadFromEnvironment(); + REQUIRE(remote_config); + SECTION("entire action output as directory") { auto const make_tree_desc = create_action({}, {""}); auto const root_desc = @@ -578,8 +591,8 @@ static inline void TestRetrieveOutputDirectories( Executor runner{repo_config, api.get(), api.get(), - RemoteExecutionConfig::PlatformProperties(), - RemoteExecutionConfig::DispatchList(), + remote_config->platform_properties, + remote_config->dispatch, auth, stats, progress}; @@ -632,8 +645,8 @@ static inline void TestRetrieveOutputDirectories( Executor runner{repo_config, api.get(), api.get(), - RemoteExecutionConfig::PlatformProperties(), - RemoteExecutionConfig::DispatchList(), + remote_config->platform_properties, + remote_config->dispatch, auth, stats, progress}; @@ -703,8 +716,8 @@ static inline void TestRetrieveOutputDirectories( Executor runner{repo_config, api.get(), api.get(), - RemoteExecutionConfig::PlatformProperties(), - RemoteExecutionConfig::DispatchList(), + remote_config->platform_properties, + remote_config->dispatch, auth, stats, progress}; @@ -776,8 +789,8 @@ static inline void TestRetrieveOutputDirectories( Executor runner{repo_config, api.get(), api.get(), - RemoteExecutionConfig::PlatformProperties(), - RemoteExecutionConfig::DispatchList(), + remote_config->platform_properties, + remote_config->dispatch, auth, stats, progress}; @@ -802,8 +815,8 @@ static inline void TestRetrieveOutputDirectories( Executor runner{repo_config, api.get(), api.get(), - RemoteExecutionConfig::PlatformProperties(), - RemoteExecutionConfig::DispatchList(), + remote_config->platform_properties, + remote_config->dispatch, auth, stats, progress}; diff --git a/test/buildtool/execution_engine/executor/executor_api_remote_bazel.test.cpp b/test/buildtool/execution_engine/executor/executor_api_remote_bazel.test.cpp index cdd47068..26054283 100755 --- a/test/buildtool/execution_engine/executor/executor_api_remote_bazel.test.cpp +++ b/test/buildtool/execution_engine/executor/executor_api_remote_bazel.test.cpp @@ -23,17 +23,25 @@ #include "src/buildtool/progress_reporting/progress.hpp" #include "test/buildtool/execution_engine/executor/executor_api.test.hpp" #include "test/utils/remote_execution/test_auth_config.hpp" +#include "test/utils/remote_execution/test_remote_config.hpp" TEST_CASE("Executor<BazelApi>: Upload blob", "[executor]") { RepositoryConfig repo_config{}; ExecutionConfiguration config; - auto const& info = RemoteExecutionConfig::RemoteAddress(); + + auto remote_config = TestRemoteConfig::ReadFromEnvironment(); + REQUIRE(remote_config); + REQUIRE(remote_config->remote_address); + auto auth_config = TestAuthConfig::ReadFromEnvironment(); REQUIRE(auth_config); TestBlobUpload(&repo_config, [&] { - return BazelApi::Ptr{new BazelApi{ - "remote-execution", info->host, info->port, &*auth_config, config}}; + return BazelApi::Ptr{new BazelApi{"remote-execution", + remote_config->remote_address->host, + remote_config->remote_address->port, + &*auth_config, + config}}; }); } @@ -44,7 +52,9 @@ TEST_CASE("Executor<BazelApi>: Compile hello world", "[executor]") { ExecutionConfiguration config; config.skip_cache_lookup = false; - auto const& info = RemoteExecutionConfig::RemoteAddress(); + auto remote_config = TestRemoteConfig::ReadFromEnvironment(); + REQUIRE(remote_config); + REQUIRE(remote_config->remote_address); auto auth_config = TestAuthConfig::ReadFromEnvironment(); REQUIRE(auth_config); @@ -54,11 +64,12 @@ TEST_CASE("Executor<BazelApi>: Compile hello world", "[executor]") { &stats, &progress, [&] { - return BazelApi::Ptr{new BazelApi{"remote-execution", - info->host, - info->port, - &*auth_config, - config}}; + return BazelApi::Ptr{ + new BazelApi{"remote-execution", + remote_config->remote_address->host, + remote_config->remote_address->port, + &*auth_config, + config}}; }, &*auth_config, false /* not hermetic */); @@ -71,7 +82,9 @@ TEST_CASE("Executor<BazelApi>: Compile greeter", "[executor]") { ExecutionConfiguration config; config.skip_cache_lookup = false; - auto const& info = RemoteExecutionConfig::RemoteAddress(); + auto remote_config = TestRemoteConfig::ReadFromEnvironment(); + REQUIRE(remote_config); + REQUIRE(remote_config->remote_address); auto auth_config = TestAuthConfig::ReadFromEnvironment(); REQUIRE(auth_config); @@ -81,11 +94,12 @@ TEST_CASE("Executor<BazelApi>: Compile greeter", "[executor]") { &stats, &progress, [&] { - return BazelApi::Ptr{new BazelApi{"remote-execution", - info->host, - info->port, - &*auth_config, - config}}; + return BazelApi::Ptr{ + new BazelApi{"remote-execution", + remote_config->remote_address->host, + remote_config->remote_address->port, + &*auth_config, + config}}; }, &*auth_config, false /* not hermetic */); @@ -98,7 +112,9 @@ TEST_CASE("Executor<BazelApi>: Upload and download trees", "[executor]") { ExecutionConfiguration config; config.skip_cache_lookup = false; - auto const& info = RemoteExecutionConfig::RemoteAddress(); + auto remote_config = TestRemoteConfig::ReadFromEnvironment(); + REQUIRE(remote_config); + REQUIRE(remote_config->remote_address); auto auth_config = TestAuthConfig::ReadFromEnvironment(); REQUIRE(auth_config); @@ -108,11 +124,12 @@ TEST_CASE("Executor<BazelApi>: Upload and download trees", "[executor]") { &stats, &progress, [&] { - return BazelApi::Ptr{new BazelApi{"remote-execution", - info->host, - info->port, - &*auth_config, - config}}; + return BazelApi::Ptr{ + new BazelApi{"remote-execution", + remote_config->remote_address->host, + remote_config->remote_address->port, + &*auth_config, + config}}; }, &*auth_config, false /* not hermetic */); @@ -125,7 +142,9 @@ TEST_CASE("Executor<BazelApi>: Retrieve output directories", "[executor]") { ExecutionConfiguration config; config.skip_cache_lookup = false; - auto const& info = RemoteExecutionConfig::RemoteAddress(); + auto remote_config = TestRemoteConfig::ReadFromEnvironment(); + REQUIRE(remote_config); + REQUIRE(remote_config->remote_address); auto auth_config = TestAuthConfig::ReadFromEnvironment(); REQUIRE(auth_config); @@ -135,11 +154,12 @@ TEST_CASE("Executor<BazelApi>: Retrieve output directories", "[executor]") { &stats, &progress, [&] { - return BazelApi::Ptr{new BazelApi{"remote-execution", - info->host, - info->port, - &*auth_config, - config}}; + return BazelApi::Ptr{ + new BazelApi{"remote-execution", + remote_config->remote_address->host, + remote_config->remote_address->port, + &*auth_config, + config}}; }, &*auth_config, false /* not hermetic */); diff --git a/test/buildtool/graph_traverser/TARGETS b/test/buildtool/graph_traverser/TARGETS index 6ed1cc1e..23a2814f 100644 --- a/test/buildtool/graph_traverser/TARGETS +++ b/test/buildtool/graph_traverser/TARGETS @@ -32,6 +32,7 @@ , ["", "catch-main"] , ["utils", "test_auth_config"] , ["utils", "test_storage_config"] + , ["@", "src", "src/buildtool/execution_api/remote", "config"] , ["@", "src", "src/buildtool/storage", "config"] , ["@", "src", "src/buildtool/storage", "storage"] ] @@ -47,6 +48,7 @@ , ["@", "catch2", "", "catch2"] , ["utils", "catch-main-remote-execution"] , ["utils", "test_auth_config"] + , ["utils", "test_remote_config"] , ["@", "src", "src/buildtool/storage", "storage"] , ["@", "src", "src/buildtool/storage", "config"] ] diff --git a/test/buildtool/graph_traverser/graph_traverser.test.hpp b/test/buildtool/graph_traverser/graph_traverser.test.hpp index b4695c34..b0187392 100644 --- a/test/buildtool/graph_traverser/graph_traverser.test.hpp +++ b/test/buildtool/graph_traverser/graph_traverser.test.hpp @@ -161,6 +161,7 @@ class TestProject { StorageConfig const& storage_config, Storage const& storage, gsl::not_null<Auth const*> const& auth, + gsl::not_null<RemoteExecutionConfig const*> const& remote_config, bool is_hermetic = true) { TestProject p("hello_world_copy_message"); @@ -173,11 +174,11 @@ class TestProject { &local_exec_config, p.GetRepoConfig(), auth, - &RemoteExecutionConfig::Instance()}; + remote_config}; GraphTraverser const gt{clargs.gtargs, p.GetRepoConfig(), - RemoteExecutionConfig::PlatformProperties(), - RemoteExecutionConfig::DispatchList(), + remote_config->platform_properties, + remote_config->dispatch, &stats, &progress, &apis, @@ -205,16 +206,15 @@ class TestProject { &local_exec_config, p.GetRepoConfig(), auth, - &RemoteExecutionConfig::Instance()}; - GraphTraverser const gt_get_exec{ - clargs_exec.gtargs, - p.GetRepoConfig(), - RemoteExecutionConfig::PlatformProperties(), - RemoteExecutionConfig::DispatchList(), - &stats, - &progress, - &apis, - [](auto done, auto cv) {}}; + remote_config}; + GraphTraverser const gt_get_exec{clargs_exec.gtargs, + p.GetRepoConfig(), + remote_config->platform_properties, + remote_config->dispatch, + &stats, + &progress, + &apis, + [](auto done, auto cv) {}}; auto const exec_result = gt_get_exec.BuildAndStage( clargs_exec.graph_description, clargs_exec.artifacts); @@ -237,6 +237,7 @@ class TestProject { StorageConfig const& storage_config, Storage const& storage, gsl::not_null<Auth const*> const& auth, + gsl::not_null<RemoteExecutionConfig const*> const& remote_config, bool is_hermetic = true) { TestProject p("copy_local_file"); @@ -249,11 +250,11 @@ class TestProject { &local_exec_config, p.GetRepoConfig(), auth, - &RemoteExecutionConfig::Instance()}; + remote_config}; GraphTraverser const gt{clargs.gtargs, p.GetRepoConfig(), - RemoteExecutionConfig::PlatformProperties(), - RemoteExecutionConfig::DispatchList(), + remote_config->platform_properties, + remote_config->dispatch, &stats, &progress, &apis, @@ -275,6 +276,7 @@ class TestProject { StorageConfig const& storage_config, Storage const& storage, gsl::not_null<Auth const*> const& auth, + gsl::not_null<RemoteExecutionConfig const*> const& remote_config, bool is_hermetic = true) { TestProject p("sequence_printer_build_library_only"); @@ -287,11 +289,11 @@ class TestProject { &local_exec_config, p.GetRepoConfig(), auth, - &RemoteExecutionConfig::Instance()}; + remote_config}; GraphTraverser const gt{clargs.gtargs, p.GetRepoConfig(), - RemoteExecutionConfig::PlatformProperties(), - RemoteExecutionConfig::DispatchList(), + remote_config->platform_properties, + remote_config->dispatch, &stats, &progress, &apis, @@ -304,15 +306,14 @@ class TestProject { CHECK(FileSystemManager::IsFile(result->output_paths.at(0))); auto const clargs_full_build = p.CmdLineArgs("_entry_points_full_build"); - GraphTraverser const gt_full_build{ - clargs_full_build.gtargs, - p.GetRepoConfig(), - RemoteExecutionConfig::PlatformProperties(), - RemoteExecutionConfig::DispatchList(), - &stats, - &progress, - &apis, - [](auto done, auto cv) {}}; + GraphTraverser const gt_full_build{clargs_full_build.gtargs, + p.GetRepoConfig(), + remote_config->platform_properties, + remote_config->dispatch, + &stats, + &progress, + &apis, + [](auto done, auto cv) {}}; auto const full_build_result = gt_full_build.BuildAndStage( clargs_full_build.graph_description, clargs_full_build.artifacts); @@ -333,6 +334,7 @@ class TestProject { StorageConfig const& storage_config, Storage const& storage, gsl::not_null<Auth const*> const& auth, + gsl::not_null<RemoteExecutionConfig const*> const& remote_config, bool is_hermetic = true) { TestProject full_hello_world("hello_world_copy_message"); @@ -346,11 +348,11 @@ class TestProject { &local_exec_config, full_hello_world.GetRepoConfig(), auth, - &RemoteExecutionConfig::Instance()}; + remote_config}; GraphTraverser const gt_upload{clargs_update_cpp.gtargs, full_hello_world.GetRepoConfig(), - RemoteExecutionConfig::PlatformProperties(), - RemoteExecutionConfig::DispatchList(), + remote_config->platform_properties, + remote_config->dispatch, &stats, &progress, &apis, @@ -372,8 +374,8 @@ class TestProject { auto const clargs = hello_world_known_cpp.CmdLineArgs(); GraphTraverser const gt{clargs.gtargs, full_hello_world.GetRepoConfig(), - RemoteExecutionConfig::PlatformProperties(), - RemoteExecutionConfig::DispatchList(), + remote_config->platform_properties, + remote_config->dispatch, &stats, &progress, &apis, @@ -394,10 +396,12 @@ class TestProject { } } -static void TestBlobsUploadedAndUsed(StorageConfig const& storage_config, - Storage const& storage, - gsl::not_null<Auth const*> const& auth, - bool is_hermetic = true) { +static void TestBlobsUploadedAndUsed( + StorageConfig const& storage_config, + Storage const& storage, + gsl::not_null<Auth const*> const& auth, + gsl::not_null<RemoteExecutionConfig const*> const& remote_config, + bool is_hermetic = true) { TestProject p("use_uploaded_blobs"); auto const clargs = p.CmdLineArgs(); @@ -409,11 +413,11 @@ static void TestBlobsUploadedAndUsed(StorageConfig const& storage_config, &local_exec_config, p.GetRepoConfig(), auth, - &RemoteExecutionConfig::Instance()}; + remote_config}; GraphTraverser gt{clargs.gtargs, p.GetRepoConfig(), - RemoteExecutionConfig::PlatformProperties(), - RemoteExecutionConfig::DispatchList(), + remote_config->platform_properties, + remote_config->dispatch, &stats, &progress, &apis, @@ -443,6 +447,7 @@ static void TestEnvironmentVariablesSetAndUsed( StorageConfig const& storage_config, Storage const& storage, gsl::not_null<Auth const*> const& auth, + gsl::not_null<RemoteExecutionConfig const*> const& remote_config, bool is_hermetic = true) { TestProject p("use_env_variables"); auto const clargs = p.CmdLineArgs(); @@ -455,11 +460,11 @@ static void TestEnvironmentVariablesSetAndUsed( &local_exec_config, p.GetRepoConfig(), auth, - &RemoteExecutionConfig::Instance()}; + remote_config}; GraphTraverser gt{clargs.gtargs, p.GetRepoConfig(), - RemoteExecutionConfig::PlatformProperties(), - RemoteExecutionConfig::DispatchList(), + remote_config->platform_properties, + remote_config->dispatch, &stats, &progress, &apis, @@ -485,10 +490,12 @@ static void TestEnvironmentVariablesSetAndUsed( } } -static void TestTreesUsed(StorageConfig const& storage_config, - Storage const& storage, - gsl::not_null<Auth const*> const& auth, - bool is_hermetic = true) { +static void TestTreesUsed( + StorageConfig const& storage_config, + Storage const& storage, + gsl::not_null<Auth const*> const& auth, + gsl::not_null<RemoteExecutionConfig const*> const& remote_config, + bool is_hermetic = true) { TestProject p("use_trees"); auto const clargs = p.CmdLineArgs(); @@ -500,11 +507,11 @@ static void TestTreesUsed(StorageConfig const& storage_config, &local_exec_config, p.GetRepoConfig(), auth, - &RemoteExecutionConfig::Instance()}; + remote_config}; GraphTraverser gt{clargs.gtargs, p.GetRepoConfig(), - RemoteExecutionConfig::PlatformProperties(), - RemoteExecutionConfig::DispatchList(), + remote_config->platform_properties, + remote_config->dispatch, &stats, &progress, &apis, @@ -530,10 +537,12 @@ static void TestTreesUsed(StorageConfig const& storage_config, } } -static void TestNestedTreesUsed(StorageConfig const& storage_config, - Storage const& storage, - gsl::not_null<Auth const*> const& auth, - bool is_hermetic = true) { +static void TestNestedTreesUsed( + StorageConfig const& storage_config, + Storage const& storage, + gsl::not_null<Auth const*> const& auth, + gsl::not_null<RemoteExecutionConfig const*> const& remote_config, + bool is_hermetic = true) { TestProject p("use_nested_trees"); auto const clargs = p.CmdLineArgs(); @@ -545,11 +554,11 @@ static void TestNestedTreesUsed(StorageConfig const& storage_config, &local_exec_config, p.GetRepoConfig(), auth, - &RemoteExecutionConfig::Instance()}; + remote_config}; GraphTraverser gt{clargs.gtargs, p.GetRepoConfig(), - RemoteExecutionConfig::PlatformProperties(), - RemoteExecutionConfig::DispatchList(), + remote_config->platform_properties, + remote_config->dispatch, &stats, &progress, &apis, @@ -575,10 +584,12 @@ static void TestNestedTreesUsed(StorageConfig const& storage_config, } } -static void TestFlakyHelloWorldDetected(StorageConfig const& storage_config, - Storage const& storage, - gsl::not_null<Auth const*> const& auth, - bool /*is_hermetic*/ = true) { +static void TestFlakyHelloWorldDetected( + StorageConfig const& storage_config, + Storage const& storage, + gsl::not_null<Auth const*> const& auth, + gsl::not_null<RemoteExecutionConfig const*> const& remote_config, + bool /*is_hermetic*/ = true) { TestProject p("flaky_hello_world"); auto const local_exec_config = CreateLocalExecConfig(); @@ -589,14 +600,14 @@ static void TestFlakyHelloWorldDetected(StorageConfig const& storage_config, &local_exec_config, p.GetRepoConfig(), auth, - &RemoteExecutionConfig::Instance()}; + remote_config}; { auto clargs = p.CmdLineArgs("_entry_points_ctimes"); GraphTraverser const gt{clargs.gtargs, p.GetRepoConfig(), - RemoteExecutionConfig::PlatformProperties(), - RemoteExecutionConfig::DispatchList(), + remote_config->platform_properties, + remote_config->dispatch, &stats, &progress, &apis, @@ -616,8 +627,8 @@ static void TestFlakyHelloWorldDetected(StorageConfig const& storage_config, clargs_output.gtargs.rebuild = RebuildArguments{}; GraphTraverser const gt_output{clargs_output.gtargs, p.GetRepoConfig(), - RemoteExecutionConfig::PlatformProperties(), - RemoteExecutionConfig::DispatchList(), + remote_config->platform_properties, + remote_config->dispatch, &stats, &progress, &apis, @@ -632,15 +643,14 @@ static void TestFlakyHelloWorldDetected(StorageConfig const& storage_config, // make_exe[flaky]->make_output[miss]->strip_time [miss] auto clargs_stripped = p.CmdLineArgs("_entry_points_stripped"); clargs_stripped.gtargs.rebuild = RebuildArguments{}; - GraphTraverser const gt_stripped{ - clargs_stripped.gtargs, - p.GetRepoConfig(), - RemoteExecutionConfig::PlatformProperties(), - RemoteExecutionConfig::DispatchList(), - &stats, - &progress, - &apis, - [](auto done, auto cv) {}}; + GraphTraverser const gt_stripped{clargs_stripped.gtargs, + p.GetRepoConfig(), + remote_config->platform_properties, + remote_config->dispatch, + &stats, + &progress, + &apis, + [](auto done, auto cv) {}}; REQUIRE(gt_stripped.BuildAndStage(clargs_stripped.graph_description, clargs_stripped.artifacts)); CHECK(stats.ActionsFlakyCounter() == 1); @@ -653,8 +663,8 @@ static void TestFlakyHelloWorldDetected(StorageConfig const& storage_config, clargs_ctimes.gtargs.rebuild = RebuildArguments{}; GraphTraverser const gt_ctimes{clargs_ctimes.gtargs, p.GetRepoConfig(), - RemoteExecutionConfig::PlatformProperties(), - RemoteExecutionConfig::DispatchList(), + remote_config->platform_properties, + remote_config->dispatch, &stats, &progress, &apis, diff --git a/test/buildtool/graph_traverser/graph_traverser_local.test.cpp b/test/buildtool/graph_traverser/graph_traverser_local.test.cpp index 007d1386..2c28323b 100644 --- a/test/buildtool/graph_traverser/graph_traverser_local.test.cpp +++ b/test/buildtool/graph_traverser/graph_traverser_local.test.cpp @@ -14,6 +14,7 @@ #include "catch2/catch_test_macros.hpp" #include "src/buildtool/auth/authentication.hpp" +#include "src/buildtool/execution_api/remote/config.hpp" #include "src/buildtool/storage/config.hpp" #include "src/buildtool/storage/storage.hpp" #include "test/buildtool/graph_traverser/graph_traverser.test.hpp" @@ -24,73 +25,88 @@ TEST_CASE("Local: Output created when entry point is local artifact", "[graph_traverser]") { auto const storage_config = TestStorageConfig::Create(); auto const storage = Storage::Create(&storage_config.Get()); - Auth auth{}; /*no TLS needed*/ + Auth auth{}; /*no TLS needed*/ + RemoteExecutionConfig remote_config{}; /*no remote*/ - TestCopyLocalFile(storage_config.Get(), storage, &auth); + TestCopyLocalFile(storage_config.Get(), storage, &auth, &remote_config); } TEST_CASE("Local: Output created and contents are correct", "[graph_traverser]") { auto const storage_config = TestStorageConfig::Create(); auto const storage = Storage::Create(&storage_config.Get()); - Auth auth{}; /*no TLS needed*/ + Auth auth{}; /*no TLS needed*/ + RemoteExecutionConfig remote_config{}; /*no remote*/ - TestHelloWorldCopyMessage(storage_config.Get(), storage, &auth); + TestHelloWorldCopyMessage( + storage_config.Get(), storage, &auth, &remote_config); } TEST_CASE("Local: Actions are not re-run", "[graph_traverser]") { auto const storage_config = TestStorageConfig::Create(); auto const storage = Storage::Create(&storage_config.Get()); - Auth auth{}; /*no TLS needed*/ + Auth auth{}; /*no TLS needed*/ + RemoteExecutionConfig remote_config{}; /*no remote*/ - TestSequencePrinterBuildLibraryOnly(storage_config.Get(), storage, &auth); + TestSequencePrinterBuildLibraryOnly( + storage_config.Get(), storage, &auth, &remote_config); } TEST_CASE("Local: KNOWN artifact", "[graph_traverser]") { auto const storage_config = TestStorageConfig::Create(); auto const storage = Storage::Create(&storage_config.Get()); - Auth auth{}; /*no TLS needed*/ + Auth auth{}; /*no TLS needed*/ + RemoteExecutionConfig remote_config{}; /*no remote*/ - TestHelloWorldWithKnownSource(storage_config.Get(), storage, &auth); + TestHelloWorldWithKnownSource( + storage_config.Get(), storage, &auth, &remote_config); } TEST_CASE("Local: Blobs uploaded and correctly used", "[graph_traverser]") { auto const storage_config = TestStorageConfig::Create(); auto const storage = Storage::Create(&storage_config.Get()); - Auth auth{}; /*no TLS needed*/ + Auth auth{}; /*no TLS needed*/ + RemoteExecutionConfig remote_config{}; /*no remote*/ - TestBlobsUploadedAndUsed(storage_config.Get(), storage, &auth); + TestBlobsUploadedAndUsed( + storage_config.Get(), storage, &auth, &remote_config); } TEST_CASE("Local: Environment variables are set and used", "[graph_traverser]") { auto const storage_config = TestStorageConfig::Create(); auto const storage = Storage::Create(&storage_config.Get()); - Auth auth{}; /*no TLS needed*/ + Auth auth{}; /*no TLS needed*/ + RemoteExecutionConfig remote_config{}; /*no remote*/ - TestEnvironmentVariablesSetAndUsed(storage_config.Get(), storage, &auth); + TestEnvironmentVariablesSetAndUsed( + storage_config.Get(), storage, &auth, &remote_config); } TEST_CASE("Local: Trees correctly used", "[graph_traverser]") { auto const storage_config = TestStorageConfig::Create(); auto const storage = Storage::Create(&storage_config.Get()); - Auth auth{}; /*no TLS needed*/ + Auth auth{}; /*no TLS needed*/ + RemoteExecutionConfig remote_config{}; /*no remote*/ - TestTreesUsed(storage_config.Get(), storage, &auth); + TestTreesUsed(storage_config.Get(), storage, &auth, &remote_config); } TEST_CASE("Local: Nested trees correctly used", "[graph_traverser]") { auto const storage_config = TestStorageConfig::Create(); auto const storage = Storage::Create(&storage_config.Get()); - Auth auth{}; /*no TLS needed*/ + Auth auth{}; /*no TLS needed*/ + RemoteExecutionConfig remote_config{}; /*no remote*/ - TestNestedTreesUsed(storage_config.Get(), storage, &auth); + TestNestedTreesUsed(storage_config.Get(), storage, &auth, &remote_config); } TEST_CASE("Local: Detect flaky actions", "[graph_traverser]") { auto const storage_config = TestStorageConfig::Create(); auto const storage = Storage::Create(&storage_config.Get()); - Auth auth{}; /*no TLS needed*/ + Auth auth{}; /*no TLS needed*/ + RemoteExecutionConfig remote_config{}; /*no remote*/ - TestFlakyHelloWorldDetected(storage_config.Get(), storage, &auth); + TestFlakyHelloWorldDetected( + storage_config.Get(), storage, &auth, &remote_config); } diff --git a/test/buildtool/graph_traverser/graph_traverser_remote.test.cpp b/test/buildtool/graph_traverser/graph_traverser_remote.test.cpp index 5fa3bc95..504b96a1 100644 --- a/test/buildtool/graph_traverser/graph_traverser_remote.test.cpp +++ b/test/buildtool/graph_traverser/graph_traverser_remote.test.cpp @@ -18,8 +18,10 @@ #include "src/buildtool/storage/storage.hpp" #include "test/buildtool/graph_traverser/graph_traverser.test.hpp" #include "test/utils/remote_execution/test_auth_config.hpp" +#include "test/utils/remote_execution/test_remote_config.hpp" -[[nodiscard]] static auto CreateConfig() -> StorageConfig { +[[nodiscard]] static auto CreateStorageConfig( + RemoteExecutionConfig const& remote_config) -> StorageConfig { auto cache_dir = FileSystemManager::GetCurrentDirectory() / "cache"; if (not FileSystemManager::RemoveDirectory(cache_dir, true) or not FileSystemManager::CreateDirectoryExclusive(cache_dir)) { @@ -30,12 +32,11 @@ } StorageConfig::Builder builder; - auto config = - builder.SetBuildRoot(cache_dir) - .SetRemoteExecutionArgs(RemoteExecutionConfig::RemoteAddress(), - RemoteExecutionConfig::PlatformProperties(), - RemoteExecutionConfig::DispatchList()) - .Build(); + auto config = builder.SetBuildRoot(cache_dir) + .SetRemoteExecutionArgs(remote_config.remote_address, + remote_config.platform_properties, + remote_config.dispatch) + .Build(); if (not config) { Logger::Log(LogLevel::Error, config.error()); std::exit(EXIT_FAILURE); @@ -45,93 +46,148 @@ TEST_CASE("Remote: Output created and contents are correct", "[graph_traverser]") { - StorageConfig const storage_config = CreateConfig(); + auto remote_config = TestRemoteConfig::ReadFromEnvironment(); + REQUIRE(remote_config); + + StorageConfig const storage_config = CreateStorageConfig(*remote_config); auto const storage = Storage::Create(&storage_config); + auto auth_config = TestAuthConfig::ReadFromEnvironment(); REQUIRE(auth_config); - TestHelloWorldCopyMessage( - storage_config, storage, &*auth_config, false /* not hermetic */); + TestHelloWorldCopyMessage(storage_config, + storage, + &*auth_config, + &*remote_config, + false /* not hermetic */); } TEST_CASE("Remote: Output created when entry point is local artifact", "[graph_traverser]") { - StorageConfig const storage_config = CreateConfig(); + auto remote_config = TestRemoteConfig::ReadFromEnvironment(); + REQUIRE(remote_config); + + StorageConfig const storage_config = CreateStorageConfig(*remote_config); auto const storage = Storage::Create(&storage_config); auto auth_config = TestAuthConfig::ReadFromEnvironment(); REQUIRE(auth_config); - TestCopyLocalFile( - storage_config, storage, &*auth_config, false /* not hermetic */); + TestCopyLocalFile(storage_config, + storage, + &*auth_config, + &*remote_config, + false /* not hermetic */); } TEST_CASE("Remote: Actions are not re-run", "[graph_traverser]") { - StorageConfig const storage_config = CreateConfig(); + auto remote_config = TestRemoteConfig::ReadFromEnvironment(); + REQUIRE(remote_config); + + StorageConfig const storage_config = CreateStorageConfig(*remote_config); auto const storage = Storage::Create(&storage_config); auto auth_config = TestAuthConfig::ReadFromEnvironment(); REQUIRE(auth_config); - TestSequencePrinterBuildLibraryOnly( - storage_config, storage, &*auth_config, false /* not hermetic */); + TestSequencePrinterBuildLibraryOnly(storage_config, + storage, + &*auth_config, + &*remote_config, + false /* not hermetic */); } TEST_CASE("Remote: KNOWN artifact", "[graph_traverser]") { - StorageConfig const storage_config = CreateConfig(); + auto remote_config = TestRemoteConfig::ReadFromEnvironment(); + REQUIRE(remote_config); + + StorageConfig const storage_config = CreateStorageConfig(*remote_config); auto const storage = Storage::Create(&storage_config); auto auth_config = TestAuthConfig::ReadFromEnvironment(); REQUIRE(auth_config); - TestHelloWorldWithKnownSource( - storage_config, storage, &*auth_config, false /* not hermetic */); + TestHelloWorldWithKnownSource(storage_config, + storage, + &*auth_config, + &*remote_config, + false /* not hermetic */); } TEST_CASE("Remote: Blobs uploaded and correctly used", "[graph_traverser]") { - StorageConfig const storage_config = CreateConfig(); + auto remote_config = TestRemoteConfig::ReadFromEnvironment(); + REQUIRE(remote_config); + + StorageConfig const storage_config = CreateStorageConfig(*remote_config); auto const storage = Storage::Create(&storage_config); auto auth_config = TestAuthConfig::ReadFromEnvironment(); REQUIRE(auth_config); - TestBlobsUploadedAndUsed( - storage_config, storage, &*auth_config, false /* not hermetic */); + TestBlobsUploadedAndUsed(storage_config, + storage, + &*auth_config, + &*remote_config, + false /* not hermetic */); } TEST_CASE("Remote: Environment variables are set and used", "[graph_traverser]") { - StorageConfig const storage_config = CreateConfig(); + auto remote_config = TestRemoteConfig::ReadFromEnvironment(); + REQUIRE(remote_config); + + StorageConfig const storage_config = CreateStorageConfig(*remote_config); auto const storage = Storage::Create(&storage_config); auto auth_config = TestAuthConfig::ReadFromEnvironment(); REQUIRE(auth_config); - TestEnvironmentVariablesSetAndUsed( - storage_config, storage, &*auth_config, false /* not hermetic */); + TestEnvironmentVariablesSetAndUsed(storage_config, + storage, + &*auth_config, + &*remote_config, + false /* not hermetic */); } TEST_CASE("Remote: Trees correctly used", "[graph_traverser]") { - StorageConfig const storage_config = CreateConfig(); + auto remote_config = TestRemoteConfig::ReadFromEnvironment(); + REQUIRE(remote_config); + + StorageConfig const storage_config = CreateStorageConfig(*remote_config); auto const storage = Storage::Create(&storage_config); auto auth_config = TestAuthConfig::ReadFromEnvironment(); REQUIRE(auth_config); - TestTreesUsed( - storage_config, storage, &*auth_config, false /* not hermetic */); + TestTreesUsed(storage_config, + storage, + &*auth_config, + &*remote_config, + false /* not hermetic */); } TEST_CASE("Remote: Nested trees correctly used", "[graph_traverser]") { - StorageConfig const storage_config = CreateConfig(); + auto remote_config = TestRemoteConfig::ReadFromEnvironment(); + REQUIRE(remote_config); + + StorageConfig const storage_config = CreateStorageConfig(*remote_config); auto const storage = Storage::Create(&storage_config); auto auth_config = TestAuthConfig::ReadFromEnvironment(); REQUIRE(auth_config); - TestNestedTreesUsed( - storage_config, storage, &*auth_config, false /* not hermetic */); + TestNestedTreesUsed(storage_config, + storage, + &*auth_config, + &*remote_config, + false /* not hermetic */); } TEST_CASE("Remote: Detect flaky actions", "[graph_traverser]") { - StorageConfig const storage_config = CreateConfig(); + auto remote_config = TestRemoteConfig::ReadFromEnvironment(); + REQUIRE(remote_config); + + StorageConfig const storage_config = CreateStorageConfig(*remote_config); auto const storage = Storage::Create(&storage_config); auto auth_config = TestAuthConfig::ReadFromEnvironment(); REQUIRE(auth_config); - TestFlakyHelloWorldDetected( - storage_config, storage, &*auth_config, false /* not hermetic */); + TestFlakyHelloWorldDetected(storage_config, + storage, + &*auth_config, + &*remote_config, + false /* not hermetic */); } diff --git a/test/utils/TARGETS b/test/utils/TARGETS index f528a5aa..8854c9ba 100644 --- a/test/utils/TARGETS +++ b/test/utils/TARGETS @@ -15,6 +15,7 @@ , ["@", "src", "src/buildtool/common", "bazel_types"] , "test_env" , "test_auth_config" + , "test_remote_config" ] , "stage": ["test", "utils"] } @@ -78,6 +79,7 @@ , "log_config" , "test_env" , "test_auth_config" + , "test_remote_config" ] , "stage": ["test", "utils"] } @@ -105,6 +107,18 @@ ] , "stage": ["test", "utils"] } +, "test_remote_config": + { "type": ["@", "rules", "CC", "library"] + , "name": ["test_remote_config"] + , "hdrs": ["remote_execution/test_remote_config.hpp"] + , "deps": + [ ["@", "src", "src/buildtool/execution_api/remote", "config"] + , ["@", "src", "src/buildtool/logging", "log_level"] + , ["@", "src", "src/buildtool/logging", "logging"] + , "test_env" + ] + , "stage": ["test", "utils"] + } , "catch-main-serve": { "type": ["@", "rules", "CC", "library"] , "name": ["catch-main-serve"] diff --git a/test/utils/remote_execution/bazel_action_creator.hpp b/test/utils/remote_execution/bazel_action_creator.hpp index 1199a385..c7b24f2b 100644 --- a/test/utils/remote_execution/bazel_action_creator.hpp +++ b/test/utils/remote_execution/bazel_action_creator.hpp @@ -29,6 +29,7 @@ #include "src/buildtool/execution_api/remote/bazel/bazel_cas_client.hpp" #include "src/buildtool/execution_api/remote/config.hpp" #include "test/utils/remote_execution/test_auth_config.hpp" +#include "test/utils/remote_execution/test_remote_config.hpp" [[nodiscard]] static inline auto CreateAction( std::string const& instance_name, @@ -36,8 +37,6 @@ std::map<std::string, std::string> const& env_vars, std::map<std::string, std::string> const& properties) noexcept -> std::unique_ptr<bazel_re::Digest> { - auto const& info = RemoteExecutionConfig::RemoteAddress(); - auto platform = std::make_unique<bazel_re::Platform>(); for (auto const& [name, value] : properties) { bazel_re::Platform_Property property; @@ -88,7 +87,14 @@ return nullptr; } - BazelCasClient cas_client(info->host, info->port, &*auth_config); + auto remote_config = TestRemoteConfig::ReadFromEnvironment(); + if (not remote_config or not remote_config->remote_address) { + return nullptr; + } + + BazelCasClient cas_client(remote_config->remote_address->host, + remote_config->remote_address->port, + &*auth_config); std::vector<gsl::not_null<BazelBlob const*>> blob_ptrs; blob_ptrs.reserve(blobs.size()); diff --git a/test/utils/remote_execution/main-remote-execution.cpp b/test/utils/remote_execution/main-remote-execution.cpp index e18ceb5a..3b4bc60e 100644 --- a/test/utils/remote_execution/main-remote-execution.cpp +++ b/test/utils/remote_execution/main-remote-execution.cpp @@ -29,6 +29,7 @@ #include "src/buildtool/logging/logger.hpp" #include "test/utils/logging/log_config.hpp" #include "test/utils/remote_execution/test_auth_config.hpp" +#include "test/utils/remote_execution/test_remote_config.hpp" #include "test/utils/test_env.hpp" namespace { @@ -41,7 +42,7 @@ void wait_for_grpc_to_shutdown() { /// \brief Configure remote execution from test environment. In case the /// environment variable is malformed, we write a message and stop execution. /// \returns true If remote execution was successfully configured. -[[nodiscard]] auto ConfigureRemoteExecution() -> bool { +void ConfigureRemoteExecution() { ReadCompatibilityFromEnv(); // Ensure authentication config is available @@ -52,19 +53,11 @@ void wait_for_grpc_to_shutdown() { HashFunction::SetHashType(Compatibility::IsCompatible() ? HashFunction::JustHash::Compatible : HashFunction::JustHash::Native); - auto address = ReadRemoteAddressFromEnv(); - if (address and not RemoteExecutionConfig::SetRemoteAddress(*address)) { - Logger::Log(LogLevel::Error, "parsing address '{}' failed.", *address); + + auto remote_config = TestRemoteConfig::ReadFromEnvironment(); + if (not remote_config or remote_config->remote_address == std::nullopt) { std::exit(EXIT_FAILURE); } - for (auto const& property : ReadPlatformPropertiesFromEnv()) { - if (not RemoteExecutionConfig::AddPlatformProperty(property)) { - Logger::Log( - LogLevel::Error, "parsing property '{}' failed.", property); - std::exit(EXIT_FAILURE); - } - } - return static_cast<bool>(RemoteExecutionConfig::RemoteAddress()); } } // namespace @@ -72,9 +65,7 @@ void wait_for_grpc_to_shutdown() { auto main(int argc, char* argv[]) -> int { ConfigureLogging(); - if (not ConfigureRemoteExecution()) { - return EXIT_FAILURE; - } + ConfigureRemoteExecution(); /** * The current implementation of libgit2 uses pthread_key_t incorrectly diff --git a/test/utils/remote_execution/test_remote_config.hpp b/test/utils/remote_execution/test_remote_config.hpp new file mode 100644 index 00000000..513b24ea --- /dev/null +++ b/test/utils/remote_execution/test_remote_config.hpp @@ -0,0 +1,44 @@ +// 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. + +#ifndef INCLUDED_SRC_TEST_UTILS_REMOTE_EXECUTION_TEST_REMOTE_CONFIG_HPP +#define INCLUDED_SRC_TEST_UTILS_REMOTE_EXECUTION_TEST_REMOTE_CONFIG_HPP + +#include <optional> + +#include "src/buildtool/execution_api/remote/config.hpp" +#include "src/buildtool/logging/log_level.hpp" +#include "src/buildtool/logging/logger.hpp" +#include "test/utils/test_env.hpp" + +class TestRemoteConfig final { + public: + [[nodiscard]] static auto ReadFromEnvironment() noexcept + -> std::optional<RemoteExecutionConfig> { + RemoteExecutionConfig::Builder builder; + auto config = + builder.SetRemoteAddress(ReadRemoteAddressFromEnv()) + .SetPlatformProperties(ReadPlatformPropertiesFromEnv()) + .Build(); + + if (config) { + return *std::move(config); + } + + Logger::Log(LogLevel::Error, config.error()); + return std::nullopt; + } +}; + +#endif // INCLUDED_SRC_TEST_UTILS_REMOTE_EXECUTION_TEST_REMOTE_CONFIG_HPP |