Skip to content

Commit

Permalink
test(samples): add backoff to cluster creation sample (#362)
Browse files Browse the repository at this point in the history
Closes #353.
  • Loading branch information
tseaver authored Jul 13, 2021
1 parent bc57c79 commit 38902c4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 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
8 changes: 6 additions & 2 deletions samples/instanceadmin/test_instanceadmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
import time
import warnings

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

import pytest

import instanceadmin
Expand Down Expand Up @@ -128,7 +129,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 38902c4

Please sign in to comment.