Skip to content

Commit 3cdddcd

Browse files
authored
Harden logging systests (#5496)
* Harden teardown against 429 TooManyRequests errors. * Harden bucket setup against 409 Conflict and 503 ServiceUnavailable errors. * Harden dataset setup against transient errors. Closes #5493, #5494.
1 parent a7ee16c commit 3cdddcd

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

tests/system/test_system.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import logging
1717
import unittest
1818

19+
from google.api_core.exceptions import BadGateway
1920
from google.api_core.exceptions import Conflict
2021
from google.api_core.exceptions import NotFound
2122
from google.api_core.exceptions import TooManyRequests
@@ -102,7 +103,7 @@ def setUp(self):
102103
self._handlers_cache = logging.getLogger().handlers[:]
103104

104105
def tearDown(self):
105-
retry = RetryErrors(NotFound, max_tries=9)
106+
retry = RetryErrors((NotFound, TooManyRequests), max_tries=9)
106107
for doomed in self.to_delete:
107108
try:
108109
retry(doomed.delete)()
@@ -381,9 +382,10 @@ def _init_storage_bucket(self):
381382

382383
# Create the destination bucket, and set up the ACL to allow
383384
# Stackdriver Logging to write into it.
385+
retry = RetryErrors((Conflict, TooManyRequests, ServiceUnavailable))
384386
storage_client = storage.Client()
385387
bucket = storage_client.bucket(BUCKET_NAME)
386-
retry_429(bucket.create)()
388+
retry(bucket.create)()
387389
self.to_delete.append(bucket)
388390
bucket.acl.reload()
389391
logs_group = bucket.acl.group('[email protected]')
@@ -441,9 +443,11 @@ def _init_bigquery_dataset(self):
441443

442444
# Create the destination dataset, and set up the ACL to allow
443445
# Stackdriver Logging to write into it.
446+
retry = RetryErrors((TooManyRequests, BadGateway, ServiceUnavailable))
444447
bigquery_client = bigquery.Client()
445448
dataset_ref = bigquery_client.dataset(dataset_name)
446-
dataset = bigquery_client.create_dataset(bigquery.Dataset(dataset_ref))
449+
dataset = retry(bigquery_client.create_dataset)(
450+
bigquery.Dataset(dataset_ref))
447451
self.to_delete.append((bigquery_client, dataset))
448452
bigquery_client.get_dataset(dataset)
449453
access = AccessEntry(

0 commit comments

Comments
 (0)