From aa540eadff01404101bb072fa5f6a29e6fe7a647 Mon Sep 17 00:00:00 2001 From: Sangram Date: Tue, 30 Jul 2019 19:27:03 +0530 Subject: [PATCH 1/3] Fix 'deadline exceeded' error for create bigtable --- bigtable/docs/snippets.py | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/bigtable/docs/snippets.py b/bigtable/docs/snippets.py index 7f4071b41fd8..922526485fc9 100644 --- a/bigtable/docs/snippets.py +++ b/bigtable/docs/snippets.py @@ -45,6 +45,7 @@ INSTANCE_ID = "snippet-tests" + UNIQUE_SUFFIX CLUSTER_ID = "clus-1-" + UNIQUE_SUFFIX APP_PROFILE_ID = "app-prof" + UNIQUE_SUFFIX +TABLE_ID = "tabl-1" + UNIQUE_SUFFIX ROUTING_POLICY_TYPE = enums.RoutingPolicyType.ANY LOCATION_ID = "us-central1-f" ALT_LOCATION_ID = "us-central1-a" @@ -72,6 +73,7 @@ class Config(object): CLIENT = None INSTANCE = None + TABLE = None def setup_module(): @@ -88,6 +90,8 @@ def setup_module(): operation = Config.INSTANCE.create(clusters=[cluster]) # We want to make sure the operation completes. operation.result(timeout=100) + Config.TABLE = Config.INSTANCE.table(TABLE_ID) + Config.TABLE.create() def teardown_module(): @@ -413,14 +417,6 @@ def test_bigtable_create_table(): def test_bigtable_list_tables(): - from google.cloud.bigtable import Client - from google.cloud.bigtable import column_family - - client = Client(admin=True) - instance = client.instance(INSTANCE_ID) - table = instance.table("to_list") - max_versions_rule = column_family.MaxVersionsGCRule(2) - table.create(column_families={"cf1": max_versions_rule}) # [START bigtable_list_tables] from google.cloud.bigtable import Client @@ -430,12 +426,6 @@ def test_bigtable_list_tables(): tables_list = instance.list_tables() # [END bigtable_list_tables] - table_names = [table.name for table in tables_list] - try: - assert table.name in table_names - finally: - retry_429(table.delete)() - def test_bigtable_delete_cluster(): from google.cloud.bigtable import Client @@ -471,9 +461,10 @@ def test_bigtable_delete_instance(): client = Client(admin=True) - instance = client.instance("inst-my-123", instance_type=PRODUCTION, labels=LABELS) + instance_id = "snipt-inst-del" + UNIQUE_SUFFIX + instance = client.instance(instance_id, instance_type=PRODUCTION, labels=LABELS) cluster = instance.cluster( - "clus-my-123", + "clus-to-delete" + UNIQUE_SUFFIX, location_id=ALT_LOCATION_ID, serve_nodes=1, default_storage_type=STORAGE_TYPE, @@ -491,7 +482,6 @@ def test_bigtable_delete_instance(): client = Client(admin=True) - instance_id = "inst-my-123" instance_to_delete = client.instance(instance_id) instance_to_delete.delete() # [END bigtable_delete_instance] From cd34a3dc7b5f1608fb9d3d7143268eacd8b32462 Mon Sep 17 00:00:00 2001 From: Sangram Date: Sat, 3 Aug 2019 03:18:17 +0530 Subject: [PATCH 2/3] Add test for list_tables --- bigtable/docs/snippets.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bigtable/docs/snippets.py b/bigtable/docs/snippets.py index 922526485fc9..5a6d66fde324 100644 --- a/bigtable/docs/snippets.py +++ b/bigtable/docs/snippets.py @@ -426,6 +426,10 @@ def test_bigtable_list_tables(): tables_list = instance.list_tables() # [END bigtable_list_tables] + # Check if returned list has expected table + table_names = [table.name for table in tables_list] + assert Config.TABLE.name in table_names + def test_bigtable_delete_cluster(): from google.cloud.bigtable import Client From 4e5ee469a48aa1003e80f1b6d0b2b7476be700d1 Mon Sep 17 00:00:00 2001 From: Sangram Date: Thu, 8 Aug 2019 18:26:52 +0530 Subject: [PATCH 3/3] add retry for table.create --- bigtable/docs/snippets.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bigtable/docs/snippets.py b/bigtable/docs/snippets.py index 5a6d66fde324..c2592f2bbf96 100644 --- a/bigtable/docs/snippets.py +++ b/bigtable/docs/snippets.py @@ -36,6 +36,7 @@ from test_utils.retry import RetryErrors from google.api_core.exceptions import NotFound from google.api_core.exceptions import TooManyRequests +from google.api_core.exceptions import DeadlineExceeded from google.cloud._helpers import UTC from google.cloud.bigtable import Client from google.cloud.bigtable import enums @@ -62,6 +63,7 @@ INSTANCES_TO_DELETE = [] retry_429 = RetryErrors(TooManyRequests, max_tries=9) +retry_504 = RetryErrors(DeadlineExceeded, max_tries=4) class Config(object): @@ -91,7 +93,7 @@ def setup_module(): # We want to make sure the operation completes. operation.result(timeout=100) Config.TABLE = Config.INSTANCE.table(TABLE_ID) - Config.TABLE.create() + retry_504(Config.TABLE.create)() def teardown_module():