Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

impl: add integration tests for LRO Start and Await methods #14377

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
Comment on lines +244 to +246
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This confused me initially. Maybe a comment like:

// Verify that the client rejects LROs with the wrong metadata type.


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
Loading