Skip to content

Commit ef044b7

Browse files
author
Takashi Matsuo
committed
lonter wait, better teardown
1 parent 9c2fec8 commit ef044b7

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

monitoring/api/v3/alerts-client/snippets_test.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import time
2020

2121
from google.api_core.exceptions import Aborted
22+
from google.api_core.exceptions import NotFound
2223
from google.api_core.exceptions import ServiceUnavailable
2324
from google.cloud import monitoring_v3
2425
import google.protobuf.json_format
@@ -44,7 +45,7 @@ def retry_if_aborted(exception):
4445
def delay_on_aborted(err, *args):
4546
if retry_if_aborted(err[1]):
4647
# add randomness for avoiding continuous conflict
47-
time.sleep(2 + (random.randint(0, 9) * 0.1))
48+
time.sleep(5 + (random.randint(0, 9) * 0.1))
4849
return True
4950
return False
5051

@@ -90,11 +91,18 @@ def __exit__(self, type, value, traceback):
9091
@retry(wait_exponential_multiplier=1000, wait_exponential_max=10000,
9192
stop_max_attempt_number=5, retry_on_exception=retry_if_aborted)
9293
def teardown():
93-
self.alert_policy_client.delete_alert_policy(
94-
self.alert_policy.name)
95-
if self.notification_channel.name:
96-
self.notification_channel_client.delete_notification_channel(
97-
self.notification_channel.name)
94+
try:
95+
self.alert_policy_client.delete_alert_policy(
96+
self.alert_policy.name)
97+
except NotFound:
98+
print("Ignored NotFound when deleting a policy.")
99+
try:
100+
if self.notification_channel.name:
101+
self.notification_channel_client\
102+
.delete_notification_channel(
103+
self.notification_channel.name)
104+
except NotFound:
105+
print("Ignored NotFound when deleting a channel.")
98106
teardown()
99107

100108

0 commit comments

Comments
 (0)