Skip to content

Commit

Permalink
lonter wait, better teardown
Browse files Browse the repository at this point in the history
  • Loading branch information
Takashi Matsuo committed Apr 8, 2020
1 parent d40777a commit f578433
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions monitoring/api/v3/alerts-client/snippets_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import time

from google.api_core.exceptions import Aborted
from google.api_core.exceptions import NotFound
from google.api_core.exceptions import ServiceUnavailable
from google.cloud import monitoring_v3
import google.protobuf.json_format
Expand All @@ -44,7 +45,7 @@ def retry_if_aborted(exception):
def delay_on_aborted(err, *args):
if retry_if_aborted(err[1]):
# add randomness for avoiding continuous conflict
time.sleep(2 + (random.randint(0, 9) * 0.1))
time.sleep(5 + (random.randint(0, 9) * 0.1))
return True
return False

Expand Down Expand Up @@ -90,11 +91,18 @@ def __exit__(self, type, value, traceback):
@retry(wait_exponential_multiplier=1000, wait_exponential_max=10000,
stop_max_attempt_number=5, retry_on_exception=retry_if_aborted)
def teardown():
self.alert_policy_client.delete_alert_policy(
self.alert_policy.name)
if self.notification_channel.name:
self.notification_channel_client.delete_notification_channel(
self.notification_channel.name)
try:
self.alert_policy_client.delete_alert_policy(
self.alert_policy.name)
except NotFound:
print("Ignored NotFound when deleting a policy.")
try:
if self.notification_channel.name:
self.notification_channel_client\
.delete_notification_channel(
self.notification_channel.name)
except NotFound:
print("Ignored NotFound when deleting a channel.")
teardown()


Expand Down

0 comments on commit f578433

Please sign in to comment.