Skip to content

Commit

Permalink
doc(samples): wrap backoff around cluster creation sample
Browse files Browse the repository at this point in the history
Closes #353.
  • Loading branch information
tseaver committed Jul 13, 2021
1 parent bc57c79 commit b0267cd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions samples/instanceadmin/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
google-cloud-bigtable==2.0.0
backoff==1.11.0
11 changes: 8 additions & 3 deletions samples/instanceadmin/test_instanceadmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
import time
import warnings

from google.cloud import bigtable

import backoff
import pytest

from google.api_core import exceptions
from google.cloud import bigtable

import instanceadmin


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

# Add a cluster to that instance
instanceadmin.add_cluster(PROJECT, INSTANCE, CLUSTER2)
# Avoid failing for "instance is currently being changed" by
# applying an exponential backoff
w_backoff = backoff.on_exception(backoff.expo, exceptions.ServiceUnavailable)
w_backoff(instanceadmin.add_cluster)(PROJECT, INSTANCE, CLUSTER2)
out = capsys.readouterr().out
assert f"Adding cluster to instance {INSTANCE}" in out
assert "Listing clusters..." in out
Expand Down

0 comments on commit b0267cd

Please sign in to comment.