Skip to content
This repository was archived by the owner on Apr 1, 2026. It is now read-only.

Commit 178da18

Browse files
committed
Merge branch 'main' into owl-bot-9e55390c-c8bd-42a3-8377-e665e862ce81
2 parents 986097d + a189acb commit 178da18

File tree

5 files changed

+53
-34
lines changed

5 files changed

+53
-34
lines changed

samples/instanceadmin/test_instanceadmin.py

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,23 @@ def test_run_instance_operations(capsys, dispose_of):
9797

9898

9999
def test_delete_instance(capsys, dispose_of):
100-
dispose_of(INSTANCE)
100+
from concurrent.futures import TimeoutError
101101

102-
# Can't delete it, it doesn't exist
103-
instanceadmin.delete_instance(PROJECT, INSTANCE)
104-
out = capsys.readouterr().out
105-
assert "Deleting instance" in out
106-
assert f"Instance {INSTANCE} does not exist" in out
102+
@backoff.on_exception(backoff.expo, TimeoutError)
103+
def _set_up_instance():
104+
dispose_of(INSTANCE)
107105

108-
# Ok, create it then
109-
instanceadmin.run_instance_operations(PROJECT, INSTANCE, CLUSTER1)
110-
capsys.readouterr() # throw away output
106+
# Can't delete it, it doesn't exist
107+
instanceadmin.delete_instance(PROJECT, INSTANCE)
108+
out = capsys.readouterr().out
109+
assert "Deleting instance" in out
110+
assert f"Instance {INSTANCE} does not exist" in out
111+
112+
# Ok, create it then
113+
instanceadmin.run_instance_operations(PROJECT, INSTANCE, CLUSTER1)
114+
capsys.readouterr() # throw away output
115+
116+
_set_up_instance()
111117

112118
# Now delete it
113119
instanceadmin.delete_instance(PROJECT, INSTANCE)
@@ -117,22 +123,29 @@ def test_delete_instance(capsys, dispose_of):
117123

118124

119125
def test_add_and_delete_cluster(capsys, dispose_of):
120-
dispose_of(INSTANCE)
126+
from concurrent.futures import TimeoutError
121127

122-
# This won't work, because the instance isn't created yet
123-
instanceadmin.add_cluster(PROJECT, INSTANCE, CLUSTER2)
124-
out = capsys.readouterr().out
125-
assert f"Instance {INSTANCE} does not exist" in out
128+
@backoff.on_exception(backoff.expo, TimeoutError)
129+
def _set_up_instance():
130+
dispose_of(INSTANCE)
126131

127-
# Get the instance created
128-
instanceadmin.run_instance_operations(PROJECT, INSTANCE, CLUSTER1)
129-
capsys.readouterr() # throw away output
132+
# This won't work, because the instance isn't created yet
133+
instanceadmin.add_cluster(PROJECT, INSTANCE, CLUSTER2)
134+
out = capsys.readouterr().out
135+
assert f"Instance {INSTANCE} does not exist" in out
136+
137+
# Get the instance created
138+
instanceadmin.run_instance_operations(PROJECT, INSTANCE, CLUSTER1)
139+
capsys.readouterr() # throw away output
140+
141+
_set_up_instance()
130142

131143
# Add a cluster to that instance
132144
# Avoid failing for "instance is currently being changed" by
133145
# applying an exponential backoff
134-
w_backoff = backoff.on_exception(backoff.expo, exceptions.ServiceUnavailable)
135-
w_backoff(instanceadmin.add_cluster)(PROJECT, INSTANCE, CLUSTER2)
146+
backoff_503 = backoff.on_exception(backoff.expo, exceptions.ServiceUnavailable)
147+
148+
backoff_503(instanceadmin.add_cluster)(PROJECT, INSTANCE, CLUSTER2)
136149
out = capsys.readouterr().out
137150
assert f"Adding cluster to instance {INSTANCE}" in out
138151
assert "Listing clusters..." in out
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
pytest==6.2.4
2+
google-cloud-testutils==1.0.0

samples/tableadmin/tableadmin_test.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
import os
1717
import uuid
1818

19+
from google.api_core import exceptions
20+
from test_utils.retry import RetryErrors
21+
1922
from tableadmin import create_table
2023
from tableadmin import delete_table
2124
from tableadmin import run_table_operations
@@ -24,11 +27,13 @@
2427
BIGTABLE_INSTANCE = os.environ['BIGTABLE_INSTANCE']
2528
TABLE_ID_FORMAT = 'tableadmin-test-{}'
2629

30+
retry_429_503 = RetryErrors(exceptions.TooManyRequests, exceptions.ServiceUnavailable)
31+
2732

2833
def test_run_table_operations(capsys):
2934
table_id = TABLE_ID_FORMAT.format(uuid.uuid4().hex[:8])
3035

31-
run_table_operations(PROJECT, BIGTABLE_INSTANCE, table_id)
36+
retry_429_503(run_table_operations)(PROJECT, BIGTABLE_INSTANCE, table_id)
3237
out, _ = capsys.readouterr()
3338

3439
assert 'Creating the ' + table_id + ' table.' in out
@@ -48,14 +53,14 @@ def test_run_table_operations(capsys):
4853
assert 'Delete a column family cf2...' in out
4954
assert 'Column family cf2 deleted successfully.' in out
5055

51-
delete_table(PROJECT, BIGTABLE_INSTANCE, table_id)
56+
retry_429_503(delete_table)(PROJECT, BIGTABLE_INSTANCE, table_id)
5257

5358

5459
def test_delete_table(capsys):
5560
table_id = TABLE_ID_FORMAT.format(uuid.uuid4().hex[:8])
56-
create_table(PROJECT, BIGTABLE_INSTANCE, table_id)
61+
retry_429_503(create_table)(PROJECT, BIGTABLE_INSTANCE, table_id)
5762

58-
delete_table(PROJECT, BIGTABLE_INSTANCE, table_id)
63+
retry_429_503(delete_table)(PROJECT, BIGTABLE_INSTANCE, table_id)
5964
out, _ = capsys.readouterr()
6065

6166
assert 'Table ' + table_id + ' exists.' in out

tests/system/_helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def _retry_on_unavailable(exc):
3333

3434

3535
retry_grpc_unavailable = retry.RetryErrors(
36-
core_exceptions.GrpcRendezvous, error_predicate=_retry_on_unavailable,
36+
core_exceptions.GrpcRendezvous, error_predicate=_retry_on_unavailable, max_tries=9,
3737
)
3838

3939

tests/system/test_instance_admin.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def _modify_app_profile_helper(
7979
)
8080

8181
operation = app_profile.update(ignore_warnings=ignore_warnings)
82-
operation.result(timeout=30)
82+
operation.result(timeout=60)
8383

8484
alt_profile = instance.app_profile(app_profile_id)
8585
alt_profile.reload()
@@ -155,7 +155,7 @@ def test_instance_create_prod(
155155

156156
operation = instance.create(clusters=[cluster])
157157
instances_to_delete.append(instance)
158-
operation.result(timeout=30) # Ensure the operation completes.
158+
operation.result(timeout=60) # Ensure the operation completes.
159159
assert instance.type_ is None
160160

161161
# Create a new instance instance and make sure it is the same.
@@ -186,7 +186,7 @@ def test_instance_create_development(
186186

187187
operation = instance.create(clusters=[cluster])
188188
instances_to_delete.append(instance)
189-
operation.result(timeout=30) # Ensure the operation completes.
189+
operation.result(timeout=60) # Ensure the operation completes.
190190

191191
# Create a new instance instance and make sure it is the same.
192192
instance_alt = admin_client.instance(alt_instance_id)
@@ -496,7 +496,7 @@ def test_instance_update_display_name_and_labels(
496496
admin_instance_populated.labels = new_labels
497497

498498
operation = admin_instance_populated.update()
499-
operation.result(timeout=30) # ensure the operation completes.
499+
operation.result(timeout=60) # ensure the operation completes.
500500

501501
# Create a new instance instance and reload it.
502502
instance_alt = admin_client.instance(admin_instance_id, labels={})
@@ -513,7 +513,7 @@ def test_instance_update_display_name_and_labels(
513513
admin_instance_populated.display_name = old_display_name
514514
admin_instance_populated.labels = instance_labels
515515
operation = admin_instance_populated.update()
516-
operation.result(timeout=30) # ensure the operation completes.
516+
operation.result(timeout=60) # ensure the operation completes.
517517

518518

519519
def test_instance_update_w_type(
@@ -536,12 +536,12 @@ def test_instance_update_w_type(
536536

537537
operation = instance.create(clusters=[cluster])
538538
instances_to_delete.append(instance)
539-
operation.result(timeout=30) # Ensure the operation completes.
539+
operation.result(timeout=60) # Ensure the operation completes.
540540

541541
instance.display_name = None
542542
instance.type_ = enums.Instance.Type.PRODUCTION
543543
operation = instance.update()
544-
operation.result(timeout=30) # ensure the operation completes.
544+
operation.result(timeout=60) # ensure the operation completes.
545545

546546
# Create a new instance instance and reload it.
547547
instance_alt = admin_client.instance(alt_instance_id)
@@ -573,7 +573,7 @@ def test_cluster_create(
573573
default_storage_type=(enums.StorageType.SSD),
574574
)
575575
operation = cluster_2.create()
576-
operation.result(timeout=30) # Ensure the operation completes.
576+
operation.result(timeout=60) # Ensure the operation completes.
577577

578578
# Create a new object instance, reload and make sure it is the same.
579579
alt_cluster = admin_instance_populated.cluster(alt_cluster_id)
@@ -603,7 +603,7 @@ def test_cluster_update(
603603
admin_cluster.serve_nodes = new_serve_nodes
604604

605605
operation = admin_cluster.update()
606-
operation.result(timeout=30) # Ensure the operation completes.
606+
operation.result(timeout=60) # Ensure the operation completes.
607607

608608
# Create a new cluster instance and reload it.
609609
alt_cluster = admin_instance_populated.cluster(admin_cluster_id)
@@ -613,4 +613,4 @@ def test_cluster_update(
613613
# Put the cluster back the way it was for the other test cases.
614614
admin_cluster.serve_nodes = serve_nodes
615615
operation = admin_cluster.update()
616-
operation.result(timeout=30) # Ensure the operation completes.
616+
operation.result(timeout=60) # Ensure the operation completes.

0 commit comments

Comments
 (0)