Skip to content

Commit 720cb45

Browse files
chore: fix the flaky list_backups test
1 parent ac1b7a5 commit 720cb45

6 files changed

Lines changed: 68 additions & 22 deletions

File tree

google-cloud-spanner/acceptance/spanner/backup_operations_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@
3434
create_job = database.create_backup backup_id, expire_time
3535
create_job.wait_until_done!
3636

37-
# All
37+
# @type [::Array<Google::Cloud::Spanner::Backup::Job>]
3838
jobs = instance.backup_operations.all.to_a
3939
_(jobs).wont_be :empty?
4040

4141
jobs.each do |job|
4242
_(job).must_be_kind_of Google::Cloud::Spanner::Backup::Job
4343

44-
unless job.error?
44+
if job.done?
4545
_(job.backup).must_be_kind_of Google::Cloud::Spanner::Backup
4646
end
4747

google-cloud-spanner/lib/google/cloud/spanner/backup/job.rb

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,14 @@ class Backup
5858
# end
5959
#
6060
class Job
61-
##
62-
# @private The `Gapic::Operation` gRPC object.
61+
# The wrapped `Gapic::Operation` object.
62+
# @private
63+
# @return [::Gapic::Operation]
6364
attr_accessor :grpc
6465

65-
##
66-
# @private The gRPC Service object.
66+
# The `Spanner::Service` reference.
67+
# @private
68+
# @return [::Google::Cloud::Spanner::Service]
6769
attr_accessor :service
6870

6971
##
@@ -265,8 +267,11 @@ def cancel_time
265267
Convert.timestamp_to_time @grpc.metadata.cancel_time
266268
end
267269

268-
##
269-
# @private New Backup::Job from a `Gapic::Operation` object.
270+
# Create a new Backup::Job from a `Gapic::Operation` object.
271+
# @param grpc [::Gapic::Operation`] The wrapped `Gapic::Operation` object.
272+
# @param service [::Google::Cloud::Spanner::Service] A `Spanner::Service` reference.
273+
# @private
274+
# @return [::Google::Cloud::Spanner::Backup::Job]
270275
def self.from_grpc grpc, service
271276
new.tap do |job|
272277
job.instance_variable_set :@grpc, grpc

google-cloud-spanner/lib/google/cloud/spanner/backup/job/list.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ class Job
3333
# {Google::Cloud::Spanner::Admin::Database.database_admin}.list_backup_operations instead.
3434
#
3535
class List < DelegateClass(::Array)
36+
# The `Spanner::Service` reference.
3637
# @private
37-
# The gRPC Service object.
38+
# @return [::Google::Cloud::Spanner::Service]
3839
attr_accessor :service
3940

4041
# @private
@@ -148,13 +149,14 @@ def all &block
148149
end
149150
end
150151

151-
##
152-
# @private
153-
#
154-
# New Backup::Job::List from a
152+
# Creates a new `Spanner::Backup::Job::List` of `Gapic::Operation` operations from a
155153
# `Gapic::PagedEnumerable<Google::Longrunning::Operation>`
156154
# object. Operation object is a backup operation.
157-
#
155+
# @param grpc [::Gapic::PagedEnumerable<::Google::Longrunning::Operation>]
156+
# Wrapped `Gapic::PagedEnumberable` reference.
157+
# @param service [::Google::Cloud::Spanner::Service] A `Spanner::Service` reference.
158+
# @private
159+
# @return [::Google::Cloud::Spanner::Backup::Job::List]
158160
def self.from_grpc grpc, service
159161
operations_client =
160162
service.databases.instance_variable_get "@operations_client"

google-cloud-spanner/lib/google/cloud/spanner/client.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2128,13 +2128,15 @@ def transaction deadline: 120, exclude_txn_from_change_streams: false,
21282128
yield tx
21292129
transaction_id = nil
21302130
transaction_id = tx.transaction_id if tx.existing_transaction?
2131-
commit_resp = @project.service.commit \
2132-
tx.session.path, tx.mutations,
2131+
commit_resp = @project.service.commit(
2132+
tx.session.path,
2133+
tx.mutations,
21332134
transaction_id: transaction_id,
21342135
exclude_txn_from_change_streams: exclude_txn_from_change_streams,
21352136
commit_options: commit_options,
21362137
request_options: request_options,
21372138
call_options: call_options
2139+
)
21382140
resp = CommitResponse.from_grpc commit_resp
21392141
commit_options ? resp : resp.timestamp
21402142
rescue GRPC::Aborted,

google-cloud-spanner/lib/google/cloud/spanner/instance.rb

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,15 @@ module Spanner
7474
# end
7575
#
7676
class Instance
77-
##
78-
# @private The gRPC Service object.
77+
# The `Spanner::Service` reference.
78+
# @private
79+
# @return [::Google::Cloud::Spanner::Service]
7980
attr_accessor :service
8081

81-
# @private Creates a new Instance instance.
82+
# Creates a new `Spanner::Instance` instance.
83+
# @param grpc [::Google::Cloud::Spanner::Admin::Instance::V1::Instance] The protobuf `V1::Instance` underlying object.
84+
# @param service [::Google::Cloud::Spanner::Service] A `Spanner::Service` reference.
85+
# @private
8286
def initialize grpc, service
8387
@grpc = grpc
8488
@service = service
@@ -957,9 +961,12 @@ def test_permissions *permissions
957961
grpc.permissions
958962
end
959963

960-
##
961-
# @private Creates a new Instance instance from a
964+
# Creates a new Instance instance from a
962965
# `Google::Cloud::Spanner::Admin::Instance::V1::Instance`.
966+
# @param grpc [::Google::Cloud::Spanner::Admin::Instance::V1::Instance] The protobuf `V1::Instance` underlying object.
967+
# @param service [::Google::Cloud::Spanner::Service] A `Spanner::Service` reference.
968+
# @private
969+
# @return [::Google::Cloud::Spanner::Instance]
963970
def self.from_grpc grpc, service
964971
new grpc, service
965972
end

google-cloud-spanner/lib/google/cloud/spanner/service.rb

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@ def list_instances token: nil, max: nil, call_options: nil
157157
paged_enum.response
158158
end
159159

160+
# Gets information about a particular instance
161+
# @param name [::String] The name of the Spanner instance, e.g. 'myinstance'
162+
# or path to the Spanner instance, e.g. `projects/myproject/instances/myinstance`.
163+
# @private
164+
# @return [::Google::Cloud::Spanner::Admin::Instance::V1::Instance]
160165
def get_instance name, call_options: nil
161166
opts = default_options call_options: call_options
162167
request = { name: instance_path(name) }
@@ -525,8 +530,8 @@ def partition_query session_name, sql, transaction, params: nil,
525530
# Example option: `:priority`.
526531
# @param call_options [::Hash, nil] Optional. A hash of values to specify the custom
527532
# call options. Example option `:timeout`.
528-
# @return [::Google::Cloud::Spanner::V1::CommitResponse]
529533
# @private
534+
# @return [::Google::Cloud::Spanner::V1::CommitResponse]
530535
def commit session_name, mutations = [],
531536
transaction_id: nil, exclude_txn_from_change_streams: false,
532537
commit_options: nil, request_options: nil, call_options: nil
@@ -717,6 +722,25 @@ def list_database_operations instance_id,
717722
databases.list_database_operations request, opts
718723
end
719724

725+
# Lists the backup `::Google::Longrunning::Operation` long-running operations in
726+
# the given instance. A backup operation has a name of the form
727+
# projects/<project>/instances/<instance>/backups/<backup>/operations/<operation>.
728+
# @param instance_id [::String] The name of the Spanner instance, e.g. 'myinstance'
729+
# or path to the Spanner instance, e.g. `projects/myproject/instances/myinstance`.
730+
# @param filter [::String, nil] Optional.
731+
# An expression that filters the list of returned backup operations.
732+
# Example filter: `done:true`.
733+
# @param page_size [::Integer, nil] Optional.
734+
# Number of operations to be returned in the response. If 0 or
735+
# less, defaults to the server's maximum allowed page size.
736+
# @param page_token [::String, nil] Optional.
737+
# If set, `page_token` should contain a value received as a `next_page_token`
738+
# from a previous `ListBackupOperationsResponse` to the same `parent`
739+
# and with the same `filter`.
740+
# @param call_options [::Hash, nil] Optional. A hash of values to specify the custom
741+
# call options. Example option `:timeout`.
742+
# @private
743+
# @return [::Gapic::PagedEnumerable<::Gapic::Operation>]
720744
def list_backup_operations instance_id,
721745
filter: nil, page_size: nil,
722746
page_token: nil,
@@ -806,6 +830,12 @@ def project_path
806830
project: project
807831
end
808832

833+
# Converts an instance name to instance path.
834+
# If an instance path is given, returns it unchanged
835+
# @param name [::String] name of the Spanner instance, e.g. 'myinstance'
836+
# or path to the Spanner instance, e.g. `projects/myproject/instances/myinstance`.
837+
# @private
838+
# @return [::String]
809839
def instance_path name
810840
return name if name.to_s.include? "/"
811841

0 commit comments

Comments
 (0)