summaryrefslogtreecommitdiff
path: root/test/buildtool/execution_api/bazel/bazel_ac_client.test.cpp
blob: 4a352a8ebe131d4e71801d33fd2ed6d11677693a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <string>

#include "catch2/catch.hpp"
#include "src/buildtool/execution_api/remote/bazel/bazel_ac_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"

auto CreateActionCacheEntry(BazelAcClient* ac_client,
                            std::string const& instance_name,
                            bazel_re::Digest const& action_id,
                            std::string const& output) {
    bazel_re::ActionResult result{};
    result.set_stdout_raw(output);
    REQUIRE(ac_client->UpdateActionResult(instance_name, action_id, result, 1));
}

// IMPORTANT: we are hiding this test case because the version of buildbarn we
// are currently using does not allow us to upload the action to the AC
// directly. The test was not failing due to a similar action being updated by
// another test (and lack of hermeticity), so it is better to disable it than to
// have it fail if we change that other test or reset the buildbarn server and
// run only the current test case. See issue#30 in
// https://rnd-gitlab-eu-c.huawei.com/germany-research-center/intelligent-cloud-technologies-laboratory/9424510-devcloud-build-tool-technology-project-de/-/issues/30
TEST_CASE("Bazel internals: AC Client", "[!hide][execution_api]") {
    auto const& info = RemoteExecutionConfig::Instance();

    BazelAcClient ac_client(info.Host(), info.Port());

    std::string instance_name{"remote-execution"};
    std::string content("test");
    auto test_digest = ArtifactDigest::Create(content);

    auto action_id = CreateAction(instance_name,
                                  {"echo", "-n", content},
                                  {},
                                  ReadPlatformPropertiesFromEnv());
    REQUIRE(action_id);

    // TODO(investigate): Upload fails due to permission issues. The BuildBarn
    // revision we are currently using seems to ignore the
    // 'allowAcUpdatesForInstances' setting.
    CreateActionCacheEntry(&ac_client, instance_name, *action_id, content);

    auto ac_result =
        ac_client.GetActionResult(instance_name, *action_id, true, true, {});
    REQUIRE(ac_result);
    CHECK(std::equal_to<bazel_re::Digest>{}(ac_result->stdout_digest(),
                                            test_digest));
}