Skip to content
This repository has been archived by the owner on Dec 31, 2023. It is now read-only.

Commit

Permalink
chore: clean up alert policies older than 1 hour in snippets test (#170)
Browse files Browse the repository at this point in the history
As a next step in troubleshooting the failure from #149, I'd like to clean up the existing alert policies in the test environment before running tests.
  • Loading branch information
parthea committed Jun 29, 2021
1 parent a942b31 commit 556b7fe
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions samples/snippets/v3/alerts-client/snippets_test.py
Expand Up @@ -14,6 +14,7 @@

from __future__ import print_function

from datetime import datetime
import random
import string
import time
Expand Down Expand Up @@ -62,6 +63,17 @@ def __init__(self):
monitoring_v3.NotificationChannelServiceClient()
)

# delete all existing policies older than 1 hour prior to testing
for policy in self.alert_policy_client.list_alert_policies(name=self.project_name):
seconds_since_creation = datetime.timestamp(datetime.utcnow())-datetime.timestamp(policy.creation_record.mutate_time)
if seconds_since_creation > 3600:
try:
self.alert_policy_client.delete_alert_policy(
name=policy.name
)
except NotFound:
print("Ignored NotFound when deleting a policy.")

def __enter__(self):
@retry(
wait_exponential_multiplier=1000,
Expand Down

0 comments on commit 556b7fe

Please sign in to comment.