Repository: googleapis/google-cloud-python

Issue:
BigQuery: 'test_extract_table_compressed' snippet flakes with 429
From: https://circleci.com/gh/GoogleCloudPlatform/google-cloud-python/7569

```python
________________________ test_extract_table_compressed _________________________

client = <google.cloud.bigquery.client.Client object at 0x7fb88a41ced0>
to_delete = []

    def test_extract_table_compressed(client, to_delete):
        from google.cloud import storage
    
        bucket_name = 'extract_shakespeare_compress_{}'.format(_millis())
        storage_client = storage.Client()
>       bucket = storage_client.create_bucket(bucket_name)  # API request

../docs/bigquery/snippets.py:2077: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
../.nox/snip-2-7/lib/python2.7/site-packages/google/cloud/storage/client.py:267: in create_bucket
    bucket.create(client=self, project=project)
../.nox/snip-2-7/lib/python2.7/site-packages/google/cloud/storage/bucket.py:299: in create
    data=properties, _target_object=self)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <google.cloud.storage._http.Connection object at 0x7fb88a428550>
method = 'POST', path = '/b', query_params = {'project': 'precise-truck-742'}
data = '{"name": "extract_shakespeare_compress_1533311715069"}'
content_type = 'application/json', headers = None, api_base_url = None
api_version = None, expect_json = True
_target_object = <Bucket: extract_shakespeare_compress_1533311715069>

    def api_request(self, method, path, query_params=None,
                    data=None, content_type=None, headers=None,
                    api_base_url=None, api_version=None,
                    expect_json=True, _target_object=None):

...
    
        if not 200 <= response.status_code < 300:
>           raise exceptions.from_http_response(response)
E           TooManyRequests: 429 POST https://www.googleapis.com/storage/v1/b?project=precise-truck-742: The project exceeded the rate limit for creating and deleting buckets.
```


Discussion:

Resolving patch:
diff --git a/docs/bigquery/snippets.py b/docs/bigquery/snippets.py
--- a/docs/bigquery/snippets.py
+++ b/docs/bigquery/snippets.py
@@ -39,7 +39,9 @@
     pyarrow = None
 
 from google.api_core import datetime_helpers
+from google.api_core.exceptions import TooManyRequests
 from google.cloud import bigquery
+from test_utils.retry import RetryErrors
 
 ORIGINAL_FRIENDLY_NAME = 'Original friendly name'
 ORIGINAL_DESCRIPTION = 'Original description'
@@ -65,6 +67,9 @@
     'WHERE state = "TX"')
 
 
+retry_429 = RetryErrors(TooManyRequests)
+
+
 @pytest.fixture(scope='module')
 def client():
     return bigquery.Client()
@@ -76,9 +81,9 @@ def to_delete(client):
     yield doomed
     for item in doomed:
         if isinstance(item, (bigquery.Dataset, bigquery.DatasetReference)):
-            client.delete_dataset(item, delete_contents=True)
+            retry_429(client.delete_dataset)(item, delete_contents=True)
         else:
-            item.delete()
+            retry_429(item.delete)()
 
 
 def _millis():
@@ -1978,7 +1983,7 @@ def test_extract_table(client, to_delete):
 
     bucket_name = 'extract_shakespeare_{}'.format(_millis())
     storage_client = storage.Client()
-    bucket = storage_client.create_bucket(bucket_name)  # API request
+    bucket = retry_429(storage_client.create_bucket)(bucket_name)  # API request
     to_delete.append(bucket)
 
     # [START bigquery_extract_table]
@@ -2015,7 +2020,7 @@ def test_extract_table_json(client, to_delete):
 
     bucket_name = 'extract_shakespeare_json_{}'.format(_millis())
     storage_client = storage.Client()
-    bucket = storage_client.create_bucket(bucket_name)  # API request
+    bucket = retry_429(storage_client.create_bucket)(bucket_name)  # API request
     to_delete.append(bucket)
 
     # [START bigquery_extract_table_json]
@@ -2050,7 +2055,7 @@ def test_extract_table_compressed(client, to_delete):
 
     bucket_name = 'extract_shakespeare_compress_{}'.format(_millis())
     storage_client = storage.Client()
-    bucket = storage_client.create_bucket(bucket_name)  # API request
+    bucket = retry_429(storage_client.create_bucket)(bucket_name)  # API request
     to_delete.append(bucket)
 
     # [START bigquery_extract_table_compressed]


Test patch: