Skip to content

Commit 15f8563

Browse files
authored
fix: making test more resistant to concurent running tests (GoogleCloudPlatform#11842)
1 parent 7698043 commit 15f8563

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

iam/cloud-client/snippets/test_roles.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
import re
1616

17+
import backoff
18+
from google.api_core.exceptions import Aborted, InvalidArgument
1719
import google.auth
1820
from google.cloud.iam_admin_v1 import GetRoleRequest, IAMClient, ListRolesRequest, Role
1921
import pytest
@@ -67,6 +69,7 @@ def test_list_roles(capsys: "pytest.CaptureFixture[str]", iam_role: str) -> None
6769
assert re.search(iam_role, out)
6870

6971

72+
@backoff.on_exception(backoff.expo, Aborted, max_tries=3)
7073
def test_edit_role(iam_role: str) -> None:
7174
client = IAMClient()
7275
name = f"projects/{PROJECT}/roles/{iam_role}"
@@ -79,6 +82,7 @@ def test_edit_role(iam_role: str) -> None:
7982
assert updated_role.title == title
8083

8184

85+
@backoff.on_exception(backoff.expo, InvalidArgument, max_tries=3)
8286
def test_disable_role(capsys: "pytest.CaptureFixture[str]", iam_role: str) -> None:
8387
disable_role(PROJECT, iam_role)
8488
client = IAMClient()

iam/cloud-client/snippets/test_service_account.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import uuid
1717

1818
import backoff
19-
from google.api_core.exceptions import InvalidArgument
19+
from google.api_core.exceptions import InvalidArgument, NotFound
2020
import google.auth
2121
from google.iam.v1 import policy_pb2
2222
import pytest
@@ -92,7 +92,7 @@ def test_service_account_set_policy(service_account: str) -> None:
9292

9393
try:
9494
new_policy = set_service_account_iam_policy(PROJECT, service_account, policy)
95-
except InvalidArgument:
95+
except (InvalidArgument, NotFound):
9696
pytest.skip("Service account was removed from outside, skipping")
9797

9898
binding_found = False
@@ -108,7 +108,7 @@ def test_service_account_rename(service_account: str) -> None:
108108
new_name = "New Name"
109109
try:
110110
account = rename_service_account(PROJECT, service_account, new_name)
111-
except InvalidArgument:
111+
except (InvalidArgument, NotFound):
112112
pytest.skip("Service account was removed from outside, skipping")
113113

114114
assert account.display_name == new_name

0 commit comments

Comments
 (0)