Skip to content

Commit 27dfdd4

Browse files
kweinmeisternicain
andauthored
test: add retries to dataproc tests (#8874)
* test: add retries to dataproc tests * reorder imports * linting Co-authored-by: nicain <[email protected]>
1 parent 48d9b2d commit 27dfdd4

File tree

4 files changed

+18
-11
lines changed

4 files changed

+18
-11
lines changed

dataproc/snippets/create_cluster_test.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@
1515
import os
1616
import uuid
1717

18-
from google.api_core.exceptions import NotFound
18+
import backoff
19+
from google.api_core.exceptions import (InternalServerError, NotFound,
20+
ServiceUnavailable)
1921
from google.cloud import dataproc_v1 as dataproc
2022
import pytest
2123

2224
import create_cluster
2325

24-
2526
PROJECT_ID = os.environ["GOOGLE_CLOUD_PROJECT"]
2627
REGION = "us-central1"
2728
CLUSTER_NAME = "py-cc-test-{}".format(str(uuid.uuid4()))
@@ -49,6 +50,7 @@ def teardown():
4950
print("Cluster already deleted")
5051

5152

53+
@backoff.on_exception(backoff.expo, (InternalServerError, ServiceUnavailable), max_tries=5)
5254
def test_cluster_create(capsys):
5355
# Wrapper function for client library function
5456
create_cluster.create_cluster(PROJECT_ID, REGION, CLUSTER_NAME)

dataproc/snippets/instantiate_inline_workflow_template_test.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@
1414

1515
import os
1616

17-
import instantiate_inline_workflow_template
17+
import backoff
18+
from google.api_core.exceptions import InternalServerError, ServiceUnavailable
1819

20+
import instantiate_inline_workflow_template
1921

2022
PROJECT_ID = os.environ["GOOGLE_CLOUD_PROJECT"]
2123
REGION = "us-central1"
2224

2325

26+
@backoff.on_exception(backoff.expo, (InternalServerError, ServiceUnavailable), max_tries=5)
2427
def test_workflows(capsys):
2528
# Wrapper function for client library function
2629
instantiate_inline_workflow_template.instantiate_inline_workflow_template(

dataproc/snippets/submit_job_test.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@
1515
import os
1616
import uuid
1717

18-
from google.api_core.exceptions import NotFound
18+
import backoff
19+
from google.api_core.exceptions import (InternalServerError, NotFound,
20+
ServiceUnavailable)
1921
from google.cloud import dataproc_v1 as dataproc
2022
import pytest
2123

2224
import submit_job
2325

24-
2526
PROJECT_ID = os.environ["GOOGLE_CLOUD_PROJECT"]
2627
REGION = "us-central1"
2728
CLUSTER_NAME = "py-sj-test-{}".format(str(uuid.uuid4()))
@@ -67,6 +68,7 @@ def setup_teardown():
6768
print("Cluster already deleted")
6869

6970

71+
@backoff.on_exception(backoff.expo, (InternalServerError, ServiceUnavailable), max_tries=5)
7072
def test_submit_job(capsys):
7173
submit_job.submit_job(PROJECT_ID, REGION, CLUSTER_NAME)
7274
out, _ = capsys.readouterr()

dataproc/snippets/update_cluster_test.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,18 @@
1515
# This sample walks a user through updating the number of clusters using the Dataproc
1616
# client library.
1717

18-
1918
import os
2019
import uuid
2120

22-
from google.api_core.exceptions import NotFound
23-
from google.cloud.dataproc_v1.services.cluster_controller.client import (
24-
ClusterControllerClient,
25-
)
21+
import backoff
22+
from google.api_core.exceptions import (InternalServerError, NotFound,
23+
ServiceUnavailable)
24+
from google.cloud.dataproc_v1.services.cluster_controller.client import \
25+
ClusterControllerClient
2626
import pytest
2727

2828
import update_cluster
2929

30-
3130
PROJECT_ID = os.environ["GOOGLE_CLOUD_PROJECT"]
3231
REGION = "us-central1"
3332
CLUSTER_NAME = f"py-cc-test-{str(uuid.uuid4())}"
@@ -74,6 +73,7 @@ def setup_teardown(cluster_client):
7473
print("Cluster already deleted")
7574

7675

76+
@backoff.on_exception(backoff.expo, (InternalServerError, ServiceUnavailable), max_tries=5)
7777
def test_update_cluster(capsys, cluster_client: ClusterControllerClient):
7878
# Wrapper function for client library function
7979
update_cluster.update_cluster(PROJECT_ID, REGION, CLUSTER_NAME, NEW_NUM_INSTANCES)

0 commit comments

Comments
 (0)