diff options
author | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2024-07-25 14:35:28 +0200 |
---|---|---|
committer | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2024-07-30 12:10:06 +0200 |
commit | 69f56ad981da59f026c83b321522ad68283934c5 (patch) | |
tree | d85218053bb97bf623b541d9bc98fc9a3b0cbb44 /test | |
parent | ab0e0b86fff94bed224f894be6b555272857e336 (diff) | |
download | justbuild-69f56ad981da59f026c83b321522ad68283934c5.tar.gz |
Pass LocalContext to LocalApi
The context is passed by not_null const pointer to avoid binding to
temporaries. The LocalApi also stores the context as const ref for
further access and passing it to LocalAction.
Diffstat (limited to 'test')
5 files changed, 125 insertions, 58 deletions
diff --git a/test/buildtool/execution_api/local/TARGETS b/test/buildtool/execution_api/local/TARGETS index 41870428..46b5abb1 100644 --- a/test/buildtool/execution_api/local/TARGETS +++ b/test/buildtool/execution_api/local/TARGETS @@ -8,6 +8,7 @@ , ["@", "src", "src/buildtool/common", "artifact_description"] , ["@", "src", "src/buildtool/common", "config"] , ["@", "src", "src/buildtool/execution_api/local", "config"] + , ["@", "src", "src/buildtool/execution_api/local", "context"] , ["@", "src", "src/buildtool/execution_api/local", "local"] , ["@", "src", "src/buildtool/file_system", "file_system_manager"] , ["@", "src", "src/buildtool/logging", "log_level"] @@ -26,6 +27,7 @@ [ ["@", "catch2", "", "catch2"] , ["", "catch-main"] , ["@", "src", "src/buildtool/execution_api/local", "config"] + , ["@", "src", "src/buildtool/execution_api/local", "context"] , ["@", "src", "src/buildtool/execution_api/local", "local"] , ["buildtool/execution_api/common", "api_test"] , ["utils", "test_storage_config"] diff --git a/test/buildtool/execution_api/local/local_api.test.cpp b/test/buildtool/execution_api/local/local_api.test.cpp index 33bd8d38..22d6bdbd 100644 --- a/test/buildtool/execution_api/local/local_api.test.cpp +++ b/test/buildtool/execution_api/local/local_api.test.cpp @@ -17,6 +17,7 @@ #include "catch2/catch_test_macros.hpp" #include "src/buildtool/execution_api/local/config.hpp" +#include "src/buildtool/execution_api/local/context.hpp" #include "src/buildtool/execution_api/local/local_api.hpp" #include "src/buildtool/storage/config.hpp" #include "src/buildtool/storage/storage.hpp" @@ -27,23 +28,15 @@ namespace { class FactoryApi final { public: explicit FactoryApi( - gsl::not_null<StorageConfig const*> const& storage_config, - gsl::not_null<Storage const*> const& storage, - gsl::not_null<LocalExecutionConfig const*> const& - local_exec_config) noexcept - : storage_config_{*storage_config}, - storage_{*storage}, - local_exec_config_{*local_exec_config} {} + gsl::not_null<LocalContext const*> const& local_context) noexcept + : local_context_{*local_context} {} [[nodiscard]] auto operator()() const -> IExecutionApi::Ptr { - return IExecutionApi::Ptr{ - new LocalApi{&storage_config_, &storage_, &local_exec_config_}}; + return IExecutionApi::Ptr{new LocalApi{&local_context_}}; } private: - StorageConfig const& storage_config_; - Storage const& storage_; - LocalExecutionConfig const& local_exec_config_; + LocalContext const& local_context_; }; } // namespace @@ -52,7 +45,11 @@ TEST_CASE("LocalAPI: No input, no output", "[execution_api]") { auto const storage_config = TestStorageConfig::Create(); auto const storage = Storage::Create(&storage_config.Get()); auto const local_exec_config = CreateLocalExecConfig(); - FactoryApi api_factory(&storage_config.Get(), &storage, &local_exec_config); + // pack the local context instances to be passed to LocalApi + LocalContext const local_context{.exec_config = &local_exec_config, + .storage_config = &storage_config.Get(), + .storage = &storage}; + FactoryApi api_factory(&local_context); TestNoInputNoOutput(api_factory, {}, /*is_hermetic=*/true); } @@ -61,7 +58,11 @@ TEST_CASE("LocalAPI: No input, create output", "[execution_api]") { auto const storage_config = TestStorageConfig::Create(); auto const storage = Storage::Create(&storage_config.Get()); auto const local_exec_config = CreateLocalExecConfig(); - FactoryApi api_factory(&storage_config.Get(), &storage, &local_exec_config); + // pack the local context instances to be passed to LocalApi + LocalContext const local_context{.exec_config = &local_exec_config, + .storage_config = &storage_config.Get(), + .storage = &storage}; + FactoryApi api_factory(&local_context); TestNoInputCreateOutput(api_factory, {}, /*is_hermetic=*/true); } @@ -70,7 +71,11 @@ TEST_CASE("LocalAPI: One input copied to output", "[execution_api]") { auto const storage_config = TestStorageConfig::Create(); auto const storage = Storage::Create(&storage_config.Get()); auto const local_exec_config = CreateLocalExecConfig(); - FactoryApi api_factory(&storage_config.Get(), &storage, &local_exec_config); + // pack the local context instances to be passed to LocalApi + LocalContext const local_context{.exec_config = &local_exec_config, + .storage_config = &storage_config.Get(), + .storage = &storage}; + FactoryApi api_factory(&local_context); TestOneInputCopiedToOutput(api_factory, {}, /*is_hermetic=*/true); } @@ -79,7 +84,11 @@ TEST_CASE("LocalAPI: Non-zero exit code, create output", "[execution_api]") { auto const storage_config = TestStorageConfig::Create(); auto const storage = Storage::Create(&storage_config.Get()); auto const local_exec_config = CreateLocalExecConfig(); - FactoryApi api_factory(&storage_config.Get(), &storage, &local_exec_config); + // pack the local context instances to be passed to LocalApi + LocalContext const local_context{.exec_config = &local_exec_config, + .storage_config = &storage_config.Get(), + .storage = &storage}; + FactoryApi api_factory(&local_context); TestNonZeroExitCodeCreateOutput(api_factory, {}); } @@ -88,7 +97,11 @@ TEST_CASE("LocalAPI: Retrieve two identical trees to path", "[execution_api]") { auto const storage_config = TestStorageConfig::Create(); auto const storage = Storage::Create(&storage_config.Get()); auto const local_exec_config = CreateLocalExecConfig(); - FactoryApi api_factory(&storage_config.Get(), &storage, &local_exec_config); + // pack the local context instances to be passed to LocalApi + LocalContext const local_context{.exec_config = &local_exec_config, + .storage_config = &storage_config.Get(), + .storage = &storage}; + FactoryApi api_factory(&local_context); TestRetrieveTwoIdenticalTreesToPath( api_factory, {}, "two_trees", /*is_hermetic=*/true); @@ -99,7 +112,11 @@ TEST_CASE("LocalAPI: Retrieve file and symlink with same content to path", auto const storage_config = TestStorageConfig::Create(); auto const storage = Storage::Create(&storage_config.Get()); auto const local_exec_config = CreateLocalExecConfig(); - FactoryApi api_factory(&storage_config.Get(), &storage, &local_exec_config); + // pack the local context instances to be passed to LocalApi + LocalContext const local_context{.exec_config = &local_exec_config, + .storage_config = &storage_config.Get(), + .storage = &storage}; + FactoryApi api_factory(&local_context); TestRetrieveFileAndSymlinkWithSameContentToPath( api_factory, {}, "file_and_symlink", /*is_hermetic=*/true); @@ -109,7 +126,11 @@ TEST_CASE("LocalAPI: Retrieve mixed blobs and trees", "[execution_api]") { auto const storage_config = TestStorageConfig::Create(); auto const storage = Storage::Create(&storage_config.Get()); auto const local_exec_config = CreateLocalExecConfig(); - FactoryApi api_factory(&storage_config.Get(), &storage, &local_exec_config); + // pack the local context instances to be passed to LocalApi + LocalContext const local_context{.exec_config = &local_exec_config, + .storage_config = &storage_config.Get(), + .storage = &storage}; + FactoryApi api_factory(&local_context); TestRetrieveMixedBlobsAndTrees( api_factory, {}, "blobs_and_trees", /*is_hermetic=*/true); @@ -119,7 +140,11 @@ TEST_CASE("LocalAPI: Create directory prior to execution", "[execution_api]") { auto const storage_config = TestStorageConfig::Create(); auto const storage = Storage::Create(&storage_config.Get()); auto const local_exec_config = CreateLocalExecConfig(); - FactoryApi api_factory(&storage_config.Get(), &storage, &local_exec_config); + // pack the local context instances to be passed to LocalApi + LocalContext const local_context{.exec_config = &local_exec_config, + .storage_config = &storage_config.Get(), + .storage = &storage}; + FactoryApi api_factory(&local_context); TestCreateDirPriorToExecution(api_factory, {}, /*is_hermetic=*/true); } diff --git a/test/buildtool/execution_api/local/local_execution.test.cpp b/test/buildtool/execution_api/local/local_execution.test.cpp index 8aea5950..a08f3b87 100644 --- a/test/buildtool/execution_api/local/local_execution.test.cpp +++ b/test/buildtool/execution_api/local/local_execution.test.cpp @@ -22,6 +22,7 @@ #include "src/buildtool/common/artifact_description.hpp" #include "src/buildtool/common/repository_config.hpp" #include "src/buildtool/execution_api/local/config.hpp" +#include "src/buildtool/execution_api/local/context.hpp" #include "src/buildtool/execution_api/local/local_api.hpp" #include "src/buildtool/file_system/file_system_manager.hpp" #include "src/buildtool/logging/log_level.hpp" @@ -64,11 +65,16 @@ namespace { TEST_CASE("LocalExecution: No input, no output", "[execution_api]") { auto const storage_config = TestStorageConfig::Create(); auto const storage = Storage::Create(&storage_config.Get()); + auto const local_exec_config = CreateLocalExecConfig(); + + // pack the local context instances to be passed to LocalApi + LocalContext const local_context{.exec_config = &local_exec_config, + .storage_config = &storage_config.Get(), + .storage = &storage}; RepositoryConfig repo_config{}; - auto const local_exec_config = CreateLocalExecConfig(); - auto api = LocalApi( - &storage_config.Get(), &storage, &local_exec_config, &repo_config); + + auto api = LocalApi(&local_context, &repo_config); std::string test_content("test"); std::vector<std::string> const cmdline = {"echo", "-n", test_content}; @@ -112,11 +118,16 @@ TEST_CASE("LocalExecution: No input, no output, env variables used", "[execution_api]") { auto const storage_config = TestStorageConfig::Create(); auto const storage = Storage::Create(&storage_config.Get()); + auto const local_exec_config = CreateLocalExecConfig(); + + // pack the local context instances to be passed to LocalApi + LocalContext const local_context{.exec_config = &local_exec_config, + .storage_config = &storage_config.Get(), + .storage = &storage}; RepositoryConfig repo_config{}; - auto const local_exec_config = CreateLocalExecConfig(); - auto api = LocalApi( - &storage_config.Get(), &storage, &local_exec_config, &repo_config); + + auto api = LocalApi(&local_context, &repo_config); std::string test_content("test from env var"); std::vector<std::string> const cmdline = { @@ -165,11 +176,16 @@ TEST_CASE("LocalExecution: No input, no output, env variables used", TEST_CASE("LocalExecution: No input, create output", "[execution_api]") { auto const storage_config = TestStorageConfig::Create(); auto const storage = Storage::Create(&storage_config.Get()); + auto const local_exec_config = CreateLocalExecConfig(); + + // pack the local context instances to be passed to LocalApi + LocalContext const local_context{.exec_config = &local_exec_config, + .storage_config = &storage_config.Get(), + .storage = &storage}; RepositoryConfig repo_config{}; - auto const local_exec_config = CreateLocalExecConfig(); - auto api = LocalApi( - &storage_config.Get(), &storage, &local_exec_config, &repo_config); + + auto api = LocalApi(&local_context, &repo_config); std::string test_content("test"); auto test_digest = ArtifactDigest::Create<ObjectType::File>( @@ -225,11 +241,16 @@ TEST_CASE("LocalExecution: No input, create output", "[execution_api]") { TEST_CASE("LocalExecution: One input copied to output", "[execution_api]") { auto const storage_config = TestStorageConfig::Create(); auto const storage = Storage::Create(&storage_config.Get()); + auto const local_exec_config = CreateLocalExecConfig(); + + // pack the local context instances to be passed to LocalApi + LocalContext const local_context{.exec_config = &local_exec_config, + .storage_config = &storage_config.Get(), + .storage = &storage}; RepositoryConfig repo_config{}; - auto const local_exec_config = CreateLocalExecConfig(); - auto api = LocalApi( - &storage_config.Get(), &storage, &local_exec_config, &repo_config); + + auto api = LocalApi(&local_context, &repo_config); std::string test_content("test"); auto test_digest = ArtifactDigest::Create<ObjectType::File>( @@ -298,11 +319,16 @@ TEST_CASE("LocalExecution: One input copied to output", "[execution_api]") { TEST_CASE("LocalExecution: Cache failed action's result", "[execution_api]") { auto const storage_config = TestStorageConfig::Create(); auto const storage = Storage::Create(&storage_config.Get()); + auto const local_exec_config = CreateLocalExecConfig(); + + // pack the local context instances to be passed to LocalApi + LocalContext const local_context{.exec_config = &local_exec_config, + .storage_config = &storage_config.Get(), + .storage = &storage}; RepositoryConfig repo_config{}; - auto const local_exec_config = CreateLocalExecConfig(); - auto api = LocalApi( - &storage_config.Get(), &storage, &local_exec_config, &repo_config); + + auto api = LocalApi(&local_context, &repo_config); auto flag = GetTestDir() / "flag"; std::vector<std::string> const cmdline = { diff --git a/test/buildtool/execution_engine/executor/TARGETS b/test/buildtool/execution_engine/executor/TARGETS index c5a9b810..58a6dbdb 100644 --- a/test/buildtool/execution_engine/executor/TARGETS +++ b/test/buildtool/execution_engine/executor/TARGETS @@ -52,6 +52,7 @@ , ["@", "src", "src/buildtool/common", "common"] , ["@", "src", "src/buildtool/common", "config"] , ["@", "src", "src/buildtool/execution_api/local", "config"] + , ["@", "src", "src/buildtool/execution_api/local", "context"] , ["@", "src", "src/buildtool/execution_api/local", "local"] , ["@", "src", "src/buildtool/execution_api/remote", "config"] , ["@", "src", "src/buildtool/execution_engine/executor", "executor"] diff --git a/test/buildtool/execution_engine/executor/executor_api_local.test.cpp b/test/buildtool/execution_engine/executor/executor_api_local.test.cpp index 4fee58da..2e1dfaa2 100644 --- a/test/buildtool/execution_engine/executor/executor_api_local.test.cpp +++ b/test/buildtool/execution_engine/executor/executor_api_local.test.cpp @@ -18,6 +18,7 @@ #include "src/buildtool/common/repository_config.hpp" #include "src/buildtool/common/statistics.hpp" #include "src/buildtool/execution_api/local/config.hpp" +#include "src/buildtool/execution_api/local/context.hpp" #include "src/buildtool/execution_api/local/local_api.hpp" #include "src/buildtool/execution_api/remote/config.hpp" #include "src/buildtool/execution_engine/executor/executor.hpp" @@ -31,20 +32,29 @@ TEST_CASE("Executor<LocalApi>: Upload blob", "[executor]") { auto const storage_config = TestStorageConfig::Create(); auto const storage = Storage::Create(&storage_config.Get()); - LocalExecutionConfig local_exec_config{}; + + // pack the local context instances to be passed to LocalApi + LocalContext const local_context{.exec_config = &local_exec_config, + .storage_config = &storage_config.Get(), + .storage = &storage}; + RepositoryConfig repo_config{}; TestBlobUpload(&repo_config, [&] { - return std::make_unique<LocalApi>( - &storage_config.Get(), &storage, &local_exec_config, &repo_config); + return std::make_unique<LocalApi>(&local_context, &repo_config); }); } TEST_CASE("Executor<LocalApi>: Compile hello world", "[executor]") { auto const storage_config = TestStorageConfig::Create(); auto const storage = Storage::Create(&storage_config.Get()); - LocalExecutionConfig local_exec_config{}; + + // pack the local context instances to be passed to LocalApi + LocalContext const local_context{.exec_config = &local_exec_config, + .storage_config = &storage_config.Get(), + .storage = &storage}; + RepositoryConfig repo_config{}; Statistics stats{}; Progress progress{}; @@ -55,10 +65,7 @@ TEST_CASE("Executor<LocalApi>: Compile hello world", "[executor]") { &stats, &progress, [&] { - return std::make_unique<LocalApi>(&storage_config.Get(), - &storage, - &local_exec_config, - &repo_config); + return std::make_unique<LocalApi>(&local_context, &repo_config); }, &*auth_config); } @@ -66,8 +73,13 @@ TEST_CASE("Executor<LocalApi>: Compile hello world", "[executor]") { TEST_CASE("Executor<LocalApi>: Compile greeter", "[executor]") { auto const storage_config = TestStorageConfig::Create(); auto const storage = Storage::Create(&storage_config.Get()); - LocalExecutionConfig local_exec_config{}; + + // pack the local context instances to be passed to LocalApi + LocalContext const local_context{.exec_config = &local_exec_config, + .storage_config = &storage_config.Get(), + .storage = &storage}; + RepositoryConfig repo_config{}; Statistics stats{}; Progress progress{}; @@ -78,10 +90,7 @@ TEST_CASE("Executor<LocalApi>: Compile greeter", "[executor]") { &stats, &progress, [&] { - return std::make_unique<LocalApi>(&storage_config.Get(), - &storage, - &local_exec_config, - &repo_config); + return std::make_unique<LocalApi>(&local_context, &repo_config); }, &*auth_config); } @@ -89,8 +98,13 @@ TEST_CASE("Executor<LocalApi>: Compile greeter", "[executor]") { TEST_CASE("Executor<LocalApi>: Upload and download trees", "[executor]") { auto const storage_config = TestStorageConfig::Create(); auto const storage = Storage::Create(&storage_config.Get()); - LocalExecutionConfig local_exec_config{}; + + // pack the local context instances to be passed to LocalApi + LocalContext const local_context{.exec_config = &local_exec_config, + .storage_config = &storage_config.Get(), + .storage = &storage}; + RepositoryConfig repo_config{}; Statistics stats{}; Progress progress{}; @@ -101,10 +115,7 @@ TEST_CASE("Executor<LocalApi>: Upload and download trees", "[executor]") { &stats, &progress, [&] { - return std::make_unique<LocalApi>(&storage_config.Get(), - &storage, - &local_exec_config, - &repo_config); + return std::make_unique<LocalApi>(&local_context, &repo_config); }, &*auth_config); } @@ -112,8 +123,13 @@ TEST_CASE("Executor<LocalApi>: Upload and download trees", "[executor]") { TEST_CASE("Executor<LocalApi>: Retrieve output directories", "[executor]") { auto const storage_config = TestStorageConfig::Create(); auto const storage = Storage::Create(&storage_config.Get()); - LocalExecutionConfig local_exec_config{}; + + // pack the local context instances to be passed to LocalApi + LocalContext const local_context{.exec_config = &local_exec_config, + .storage_config = &storage_config.Get(), + .storage = &storage}; + RepositoryConfig repo_config{}; Statistics stats{}; Progress progress{}; @@ -124,10 +140,7 @@ TEST_CASE("Executor<LocalApi>: Retrieve output directories", "[executor]") { &stats, &progress, [&] { - return std::make_unique<LocalApi>(&storage_config.Get(), - &storage, - &local_exec_config, - &repo_config); + return std::make_unique<LocalApi>(&local_context, &repo_config); }, &*auth_config); } |