diff options
author | Klaus Aehlig <klaus.aehlig@huawei.com> | 2022-02-22 17:03:21 +0100 |
---|---|---|
committer | Klaus Aehlig <klaus.aehlig@huawei.com> | 2022-02-22 17:03:21 +0100 |
commit | 619def44c1cca9f3cdf63544d5f24f2c7a7d9b77 (patch) | |
tree | 01868de723cb82c86842f33743fa7b14e24c1fa3 /test/buildtool/execution_api/bazel/bazel_execution_client.test.cpp | |
download | justbuild-619def44c1cca9f3cdf63544d5f24f2c7a7d9b77.tar.gz |
Initial self-hosting commit
This is the initial version of our tool that is able to
build itself. In can be bootstrapped by
./bin/bootstrap.py
Co-authored-by: Oliver Reiche <oliver.reiche@huawei.com>
Co-authored-by: Victor Moreno <victor.moreno1@huawei.com>
Diffstat (limited to 'test/buildtool/execution_api/bazel/bazel_execution_client.test.cpp')
-rwxr-xr-x | test/buildtool/execution_api/bazel/bazel_execution_client.test.cpp | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/test/buildtool/execution_api/bazel/bazel_execution_client.test.cpp b/test/buildtool/execution_api/bazel/bazel_execution_client.test.cpp new file mode 100755 index 00000000..a80eb1af --- /dev/null +++ b/test/buildtool/execution_api/bazel/bazel_execution_client.test.cpp @@ -0,0 +1,102 @@ +#include <string> + +#include "catch2/catch.hpp" +#include "src/buildtool/execution_api/remote/bazel/bazel_execution_client.hpp" +#include "src/buildtool/execution_api/remote/config.hpp" +#include "test/utils/remote_execution/bazel_action_creator.hpp" +#include "test/utils/test_env.hpp" + +TEST_CASE("Bazel internals: Execution Client", "[execution_api]") { + auto const& info = RemoteExecutionConfig::Instance(); + + std::string instance_name{"remote-execution"}; + std::string content("test"); + auto test_digest = ArtifactDigest::Create(content); + + BazelExecutionClient execution_client(info.Host(), info.Port()); + + ExecutionConfiguration config; + config.skip_cache_lookup = false; + + SECTION("Immediate execution and response") { + auto action_immediate = CreateAction(instance_name, + {"echo", "-n", content}, + {}, + ReadPlatformPropertiesFromEnv()); + REQUIRE(action_immediate); + + auto response = execution_client.Execute( + instance_name, *action_immediate, config, true); + + REQUIRE(response.state == + BazelExecutionClient::ExecutionResponse::State::Finished); + REQUIRE(response.output); + + CHECK(response.output->action_result.stdout_digest().hash() == + test_digest.hash()); + } + + SECTION("Delayed execution") { + auto action_delayed = + CreateAction(instance_name, + {"sh", "-c", "sleep 1s; echo -n test"}, + {}, + ReadPlatformPropertiesFromEnv()); + + SECTION("Blocking, immediately obtain result") { + auto response = execution_client.Execute( + instance_name, *action_delayed, config, true); + + REQUIRE(response.state == + BazelExecutionClient::ExecutionResponse::State::Finished); + REQUIRE(response.output); + + CHECK(response.output->action_result.stdout_digest().hash() == + test_digest.hash()); + } + + SECTION("Non-blocking, obtain result later") { + auto response = execution_client.Execute( + instance_name, *action_delayed, config, false); + + REQUIRE(response.state == + BazelExecutionClient::ExecutionResponse::State::Ongoing); + response = + execution_client.WaitExecution(response.execution_handle); + REQUIRE(response.output); + + CHECK(response.output->action_result.stdout_digest().hash() == + test_digest.hash()); + } + } +} + +TEST_CASE("Bazel internals: Execution Client using env variables", + "[execution_api]") { + auto const& info = RemoteExecutionConfig::Instance(); + + std::string instance_name{"remote-execution"}; + std::string content("contents of env variable"); + auto test_digest = ArtifactDigest::Create(content); + + BazelExecutionClient execution_client(info.Host(), info.Port()); + + ExecutionConfiguration config; + config.skip_cache_lookup = false; + auto action = + CreateAction(instance_name, + {"/bin/sh", "-c", "set -e\necho -n ${MYTESTVAR}"}, + {{"MYTESTVAR", content}}, + ReadPlatformPropertiesFromEnv()); + REQUIRE(action); + + auto response = + execution_client.Execute(instance_name, *action, config, true); + + REQUIRE(response.state == + BazelExecutionClient::ExecutionResponse::State::Finished); + REQUIRE(response.output); + + CHECK(response.output->action_result.stdout_digest().hash() == + test_digest.hash()); +} |