From 860b79e7f7cf3c1b23cfe1861b8c1c440924aaa6 Mon Sep 17 00:00:00 2001 From: bradmiro Date: Mon, 22 Feb 2021 15:32:44 -0500 Subject: [PATCH] adding backoff to quickstart test --- samples/snippets/quickstart/quickstart_test.py | 11 ++++++++++- samples/snippets/requirements.txt | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/samples/snippets/quickstart/quickstart_test.py b/samples/snippets/quickstart/quickstart_test.py index 38ae8b89..6369c99c 100644 --- a/samples/snippets/quickstart/quickstart_test.py +++ b/samples/snippets/quickstart/quickstart_test.py @@ -15,6 +15,8 @@ import os import uuid +import backoff +from google.api_core.exceptions import ServiceUnavailable from google.cloud import dataproc_v1 as dataproc from google.cloud import storage import pytest @@ -39,7 +41,14 @@ @pytest.fixture(autouse=True) def setup_teardown(): storage_client = storage.Client() - bucket = storage_client.create_bucket(STAGING_BUCKET) + + @backoff.on_exception(backoff.expo, + ServiceUnavailable, + max_tries=5) + def create_bucket(): + return storage_client.create_bucket(STAGING_BUCKET) + + bucket = create_bucket() blob = bucket.blob(JOB_FILE_NAME) blob.upload_from_string(SORT_CODE) diff --git a/samples/snippets/requirements.txt b/samples/snippets/requirements.txt index 1841063b..7530efbf 100644 --- a/samples/snippets/requirements.txt +++ b/samples/snippets/requirements.txt @@ -1,3 +1,4 @@ +backoff==1.10.0 grpcio==1.35.0 google-auth==1.27.0 google-auth-httplib2==0.0.4