3636from test_utils .retry import RetryErrors
3737from google .api_core .exceptions import NotFound
3838from google .api_core .exceptions import TooManyRequests
39+ from google .api_core .exceptions import DeadlineExceeded
3940from google .cloud ._helpers import UTC
4041from google .cloud .bigtable import Client
4142from google .cloud .bigtable import enums
4546INSTANCE_ID = "snippet-tests" + UNIQUE_SUFFIX
4647CLUSTER_ID = "clus-1-" + UNIQUE_SUFFIX
4748APP_PROFILE_ID = "app-prof" + UNIQUE_SUFFIX
49+ TABLE_ID = "tabl-1" + UNIQUE_SUFFIX
4850ROUTING_POLICY_TYPE = enums .RoutingPolicyType .ANY
4951LOCATION_ID = "us-central1-f"
5052ALT_LOCATION_ID = "us-central1-a"
6163INSTANCES_TO_DELETE = []
6264
6365retry_429 = RetryErrors (TooManyRequests , max_tries = 9 )
66+ retry_504 = RetryErrors (DeadlineExceeded , max_tries = 4 )
6467
6568
6669class Config (object ):
@@ -72,6 +75,7 @@ class Config(object):
7275
7376 CLIENT = None
7477 INSTANCE = None
78+ TABLE = None
7579
7680
7781def setup_module ():
@@ -88,6 +92,8 @@ def setup_module():
8892 operation = Config .INSTANCE .create (clusters = [cluster ])
8993 # We want to make sure the operation completes.
9094 operation .result (timeout = 100 )
95+ Config .TABLE = Config .INSTANCE .table (TABLE_ID )
96+ retry_504 (Config .TABLE .create )()
9197
9298
9399def teardown_module ():
@@ -421,14 +427,6 @@ def test_bigtable_create_table():
421427
422428
423429def test_bigtable_list_tables ():
424- from google .cloud .bigtable import Client
425- from google .cloud .bigtable import column_family
426-
427- client = Client (admin = True )
428- instance = client .instance (INSTANCE_ID )
429- table = instance .table ("to_list" )
430- max_versions_rule = column_family .MaxVersionsGCRule (2 )
431- table .create (column_families = {"cf1" : max_versions_rule })
432430
433431 # [START bigtable_list_tables]
434432 from google .cloud .bigtable import Client
@@ -438,11 +436,9 @@ def test_bigtable_list_tables():
438436 tables_list = instance .list_tables ()
439437 # [END bigtable_list_tables]
440438
439+ # Check if returned list has expected table
441440 table_names = [table .name for table in tables_list ]
442- try :
443- assert table .name in table_names
444- finally :
445- retry_429 (table .delete )()
441+ assert Config .TABLE .name in table_names
446442
447443
448444def test_bigtable_delete_cluster ():
@@ -479,9 +475,10 @@ def test_bigtable_delete_instance():
479475
480476 client = Client (admin = True )
481477
482- instance = client .instance ("inst-my-123" , instance_type = PRODUCTION , labels = LABELS )
478+ instance_id = "snipt-inst-del" + UNIQUE_SUFFIX
479+ instance = client .instance (instance_id , instance_type = PRODUCTION , labels = LABELS )
483480 cluster = instance .cluster (
484- "clus-my-123" ,
481+ "clus-to-delete" + UNIQUE_SUFFIX ,
485482 location_id = ALT_LOCATION_ID ,
486483 serve_nodes = 1 ,
487484 default_storage_type = STORAGE_TYPE ,
@@ -499,7 +496,6 @@ def test_bigtable_delete_instance():
499496
500497 client = Client (admin = True )
501498
502- instance_id = "inst-my-123"
503499 instance_to_delete = client .instance (instance_id )
504500 instance_to_delete .delete ()
505501 # [END bigtable_delete_instance]
0 commit comments