Skip to content

Commit

Permalink
Merge pull request #2333 from tseaver/2318-bigquery-dataset-still-in-use
Browse files Browse the repository at this point in the history
Retry 400s during dataset teardown.
  • Loading branch information
tseaver committed Sep 16, 2016
2 parents 089138e + 0ac2ea5 commit 613361c
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions system_tests/bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import unittest

from google.cloud import bigquery
from google.cloud.exceptions import Conflict
from google.cloud.exceptions import Forbidden

from retry import RetryErrors
Expand All @@ -35,6 +34,7 @@ def _rate_limit_exceeded(forbidden):
return any(error['reason'] == 'rateLimitExceeded'
for error in forbidden._errors)


# We need to wait to stay within the rate limits.
# The alternative outcome is a 403 Forbidden response from upstream, which
# they return instead of the more appropriate 429.
Expand All @@ -61,11 +61,22 @@ def setUp(self):
self.to_delete = []

def tearDown(self):
from google.cloud.bigquery.dataset import Dataset
from google.cloud.storage import Bucket
from google.cloud.exceptions import BadRequest
from google.cloud.exceptions import Conflict

def _still_in_use(bad_request):
return any(error['reason'] == 'resourceInUse'
for error in bad_request._errors)

retry_in_use = RetryErrors(BadRequest, error_predicate=_still_in_use)
retry_409 = RetryErrors(Conflict)
for doomed in self.to_delete:
if isinstance(doomed, Bucket):
retry = RetryErrors(Conflict)
retry(doomed.delete)(force=True)
retry_409(doomed.delete)(force=True)
elif isinstance(doomed, Dataset):
retry_in_use(doomed.delete)()
else:
doomed.delete()

Expand Down

0 comments on commit 613361c

Please sign in to comment.