summaryrefslogtreecommitdiff
path: root/test/buildtool/execution_api/bazel/bazel_execution_client.test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/buildtool/execution_api/bazel/bazel_execution_client.test.cpp')
-rwxr-xr-xtest/buildtool/execution_api/bazel/bazel_execution_client.test.cpp102
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());
+}