Skip to content

Commit a90b48d

Browse files
authored
fix: rework teardown logic to work correctly with backoff strategy (GoogleCloudPlatform#9823)
* fix: Switch to different subnetwork and rework teardown logic to work correctly with backoff strategy * chore: update for linting
1 parent 22a037e commit a90b48d

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

dataproc/snippets/create_cluster_test.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,16 @@
1919
from google.api_core.exceptions import (InternalServerError, InvalidArgument, NotFound,
2020
ServiceUnavailable)
2121
from google.cloud import dataproc_v1 as dataproc
22-
import pytest
2322

2423
import create_cluster
2524

2625
PROJECT_ID = os.environ["GOOGLE_CLOUD_PROJECT"]
27-
REGION = "us-central1"
26+
REGION = "us-west1"
2827
CLUSTER_NAME = "py-cc-test-{}".format(str(uuid.uuid4()))
2928

3029

31-
@pytest.fixture(autouse=True)
30+
@backoff.on_exception(backoff.expo, (Exception), max_tries=5)
3231
def teardown():
33-
yield
34-
3532
cluster_client = dataproc.ClusterControllerClient(
3633
client_options={"api_endpoint": f"{REGION}-dataproc.googleapis.com:443"}
3734
)
@@ -54,7 +51,10 @@ def teardown():
5451
@backoff.on_exception(backoff.expo, (InternalServerError, ServiceUnavailable, InvalidArgument), max_tries=5)
5552
def test_cluster_create(capsys):
5653
# Wrapper function for client library function
57-
create_cluster.create_cluster(PROJECT_ID, REGION, CLUSTER_NAME)
54+
try:
55+
create_cluster.create_cluster(PROJECT_ID, REGION, CLUSTER_NAME)
56+
finally:
57+
teardown()
5858

5959
out, _ = capsys.readouterr()
6060
assert CLUSTER_NAME in out

0 commit comments

Comments
 (0)