Skip to content

Commit

Permalink
impl: add integration tests for LRO Start and Await methods (#14377)
Browse files Browse the repository at this point in the history
  • Loading branch information
scotthart authored Jun 27, 2024
1 parent e2d4965 commit 8d01ae3
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 3 deletions.
19 changes: 16 additions & 3 deletions google/cloud/compute/integration_tests/compute_integration_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,21 @@ TEST_F(ComputeIntegrationTest, CreateDisks) {
disk.set_name(CreateRandomName("int-test-disk-"));
disk.set_size_gb("10");
(*disk.mutable_labels())["test"] = "test";
auto result = client.InsertDisk(project_id_, zone_, disk).get();
ASSERT_THAT(result, testing_util::IsOk());
auto start_result = client.InsertDisk(ExperimentalTag{}, NoAwaitTag{},
project_id_, zone_, disk);
ASSERT_THAT(start_result, IsOk());

// Exercise serialization and deserialization to mimic the use case where the
// returned operation is stored elsewhere, the process ends, and then another
// process is started that uses the serialized string to resume waiting on the
// LRO to finish.
std::string operation_string;
EXPECT_TRUE(start_result->SerializeToString(&operation_string));
google::cloud::cpp::compute::v1::Operation operation;
EXPECT_TRUE(operation.ParseFromString(operation_string));

auto await_result = client.InsertDisk(ExperimentalTag{}, operation).get();
ASSERT_THAT(await_result, IsOk());

auto get_disk = client.GetDisk(project_id_, zone_, disk.name());
ASSERT_THAT(get_disk, IsOk());
Expand Down Expand Up @@ -151,7 +164,7 @@ TEST_F(ComputeIntegrationTest, VerifyUpdateSendsUpdateMaskParameter) {
disk.set_size_gb("10");
(*disk.mutable_labels())["test"] = "test";
auto result = client.InsertDisk(project_id_, zone_, disk).get();
ASSERT_THAT(result, testing_util::IsOk());
ASSERT_THAT(result, IsOk());

google::cloud::cpp::compute::v1::Disk disk_update = disk;
disk_update.mutable_labels()->clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,44 @@ TEST_F(InstanceAdminClientTest, InstanceCRUDOperations) {
EXPECT_STATUS_OK(client_.DeleteInstance(in.FullName()));
}

TEST_F(InstanceAdminClientTest, CreateInstanceStartAwait) {
if (!Emulator() && !RunSlowInstanceTests()) {
GTEST_SKIP() << "skipping slow instance tests; set "
<< "GOOGLE_CLOUD_CPP_SPANNER_SLOW_INTEGRATION_TESTS=instance"
<< " to override";
}

Instance in(ProjectId(), spanner_testing::RandomInstanceName(generator_));

auto config_name = spanner_testing::PickInstanceConfig(
in.project(), generator_,
[](google::spanner::admin::instance::v1::InstanceConfig const& config) {
return absl::StrContains(config.name(), "/regional-us-west");
});
ASSERT_FALSE(config_name.empty()) << "could not get an instance config";

auto operation =
client_.CreateInstance(ExperimentalTag{}, NoAwaitTag{},
CreateInstanceRequestBuilder(in, config_name)
.SetDisplayName("test-display-name")
.SetNodeCount(1)
.SetLabels({{"label-key", "label-value"}})
.Build());
ASSERT_STATUS_OK(operation);

// Verify that an error is returned if there is a mismatch between the rpc
// that returned the operation and the rpc in which is it used.
auto instance_config =
client_.CreateInstanceConfig(ExperimentalTag{}, *operation).get();
EXPECT_THAT(instance_config, StatusIs(StatusCode::kInvalidArgument));

auto instance = client_.CreateInstance(ExperimentalTag{}, *operation).get();
ASSERT_STATUS_OK(instance);
EXPECT_EQ(instance->name(), in.FullName());
EXPECT_EQ(instance->display_name(), "test-display-name");
EXPECT_STATUS_OK(client_.DeleteInstance(in.FullName()));
}

TEST_F(InstanceAdminClientTest, InstanceConfig) {
auto project_id = ProjectId();
ASSERT_FALSE(project_id.empty());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
namespace {

using ::google::cloud::testing_util::StatusIs;
using ::testing::Eq;

std::string const& ProjectId() {
static std::string project_id =
Expand Down Expand Up @@ -257,6 +258,41 @@ TEST_F(InstanceAdminClientRestTest, InstanceCRUDOperations) {
EXPECT_STATUS_OK(client_.DeleteInstance(in.FullName()));
}

TEST_F(InstanceAdminClientRestTest, CreateInstanceStartAwait) {
if (!Emulator() && !RunSlowInstanceTests()) {
GTEST_SKIP() << "skipping slow instance tests; set "
<< "GOOGLE_CLOUD_CPP_SPANNER_SLOW_INTEGRATION_TESTS=instance"
<< " to override";
}

Instance in(ProjectId(), spanner_testing::RandomInstanceName(generator_));

auto config_name = spanner_testing::PickInstanceConfig(
in.project(), generator_,
[](google::spanner::admin::instance::v1::InstanceConfig const& config) {
return absl::StrContains(config.name(), "/regional-us-west");
});
ASSERT_FALSE(config_name.empty()) << "could not get an instance config";

auto operation =
client_.CreateInstance(ExperimentalTag{}, NoAwaitTag{},
CreateInstanceRequestBuilder(in, config_name)
.SetDisplayName("test-display-name")
.SetNodeCount(1)
.SetLabels({{"label-key", "label-value"}})
.Build());
ASSERT_STATUS_OK(operation);
auto instance_config =
client_.CreateInstanceConfig(ExperimentalTag{}, *operation).get();
EXPECT_THAT(instance_config, StatusIs(StatusCode::kInvalidArgument));

auto instance = client_.CreateInstance(ExperimentalTag{}, *operation).get();
ASSERT_STATUS_OK(instance);
EXPECT_EQ(instance->name(), in.FullName());
EXPECT_EQ(instance->display_name(), "test-display-name");
EXPECT_STATUS_OK(client_.DeleteInstance(in.FullName()));
}

} // namespace
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
} // namespace spanner
Expand Down

0 comments on commit 8d01ae3

Please sign in to comment.