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

Commit b0267cd

Browse files
committed
doc(samples): wrap backoff around cluster creation sample
Closes #353.
1 parent bc57c79 commit b0267cd

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

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

samples/instanceadmin/test_instanceadmin.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717
import time
1818
import warnings
1919

20-
from google.cloud import bigtable
21-
20+
import backoff
2221
import pytest
2322

23+
from google.api_core import exceptions
24+
from google.cloud import bigtable
25+
2426
import instanceadmin
2527

2628

@@ -128,7 +130,10 @@ def test_add_and_delete_cluster(capsys, dispose_of):
128130
capsys.readouterr() # throw away output
129131

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

0 commit comments

Comments
 (0)