Skip to content

Commit 72c72db

Browse files
fix: test cleanup stages with try finally (#212)
* fix: test cleanup stages with try finally * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent cae7f4d commit 72c72db

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

container/snippets/create_cluster_test.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,23 @@ def setup_and_tear_down() -> None:
3737
# run the tests here
3838
yield
3939

40-
# delete the cluster
41-
client = gke.ClusterManagerClient()
42-
cluster_location = client.common_location_path(PROJECT_ID, ZONE)
43-
cluster_name = f"{cluster_location}/clusters/{CLUSTER_NAME}"
44-
op = client.delete_cluster({"name": cluster_name})
45-
op_id = f"{cluster_location}/operations/{op.name}"
46-
47-
# schedule a retry to ensure the cluster is deleted
48-
@backoff.on_predicate(
49-
backoff.expo, lambda x: x != gke.Operation.Status.DONE, max_tries=20
50-
)
51-
def wait_for_delete() -> gke.Operation.Status:
52-
return client.get_operation({"name": op_id}).status
53-
54-
wait_for_delete()
40+
try:
41+
# delete the cluster
42+
client = gke.ClusterManagerClient()
43+
cluster_location = client.common_location_path(PROJECT_ID, ZONE)
44+
cluster_name = f"{cluster_location}/clusters/{CLUSTER_NAME}"
45+
op = client.delete_cluster({"name": cluster_name})
46+
op_id = f"{cluster_location}/operations/{op.name}"
47+
48+
finally:
49+
# schedule a retry to ensure the cluster is deleted
50+
@backoff.on_predicate(
51+
backoff.expo, lambda x: x != gke.Operation.Status.DONE, max_tries=20
52+
)
53+
def wait_for_delete() -> gke.Operation.Status:
54+
return client.get_operation({"name": op_id}).status
55+
56+
wait_for_delete()
5557

5658

5759
def test_create_clusters(capsys: object) -> None:

0 commit comments

Comments
 (0)