Skip to content

Commit 79c5e54

Browse files
partheadandhlee
authored andcommitted
chore: add retry in test_list_alert_policies snippets test (#163)
1 parent f95c6af commit 79c5e54

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,20 @@ def pochan():
123123

124124

125125
def test_list_alert_policies(capsys, pochan):
126-
snippets.list_alert_policies(pochan.project_name)
127-
out, _ = capsys.readouterr()
128-
# Only check up to the first 20 characters of the display name
129-
# as long strings printed to the console are truncated.
130-
assert pochan.alert_policy.display_name[0:20] in out
126+
# Query snippets.list_alert_policies() for up to 5 seconds
127+
# to allow the newly created policy to appear in the list.
128+
retry = 5
129+
while retry:
130+
snippets.list_alert_policies(pochan.project_name)
131+
out, _ = capsys.readouterr()
132+
# Only check up to the first 20 characters of the display name
133+
# as long strings printed to the console are truncated.
134+
if pochan.alert_policy.display_name[0:20] in out:
135+
break
136+
retry = retry - 1
137+
time.sleep(1)
138+
139+
assert retry > 0
131140

132141

133142
@pytest.mark.flaky(rerun_filter=delay_on_aborted, max_runs=5)

0 commit comments

Comments
 (0)