Skip to content

Commit cc2eb38

Browse files
authored
test(samples): add backoff to cluster creation sample (#362)
Closes #353.
1 parent 9c48fc6 commit cc2eb38

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
google-cloud-bigtable==2.0.0
2+
backoff==1.11.0

packages/google-cloud-bigtable/samples/instanceadmin/test_instanceadmin.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
import time
1818
import warnings
1919

20+
import backoff
21+
from google.api_core import exceptions
2022
from google.cloud import bigtable
21-
2223
import pytest
2324

2425
import instanceadmin
@@ -128,7 +129,10 @@ def test_add_and_delete_cluster(capsys, dispose_of):
128129
capsys.readouterr() # throw away output
129130

130131
# Add a cluster to that instance
131-
instanceadmin.add_cluster(PROJECT, INSTANCE, CLUSTER2)
132+
# Avoid failing for "instance is currently being changed" by
133+
# applying an exponential backoff
134+
w_backoff = backoff.on_exception(backoff.expo, exceptions.ServiceUnavailable)
135+
w_backoff(instanceadmin.add_cluster)(PROJECT, INSTANCE, CLUSTER2)
132136
out = capsys.readouterr().out
133137
assert f"Adding cluster to instance {INSTANCE}" in out
134138
assert "Listing clusters..." in out

0 commit comments

Comments
 (0)