Skip to content

Commit 28105e8

Browse files
feat(uptime): Add flapping evaluate test for safety (#94346)
The stateful detector should handle this test case, but just to be safe for uptime, let's check this here as well
1 parent 5d65d7d commit 28105e8

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

tests/sentry/uptime/test_grouptype.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
from datetime import datetime, timedelta
2+
from itertools import cycle
23
from unittest import mock
34

45
import pytest
56
from jsonschema import ValidationError
6-
from sentry_kafka_schemas.schema_types.uptime_results_v1 import CheckResult
7+
from sentry_kafka_schemas.schema_types.uptime_results_v1 import (
8+
CHECKSTATUS_FAILURE,
9+
CHECKSTATUS_SUCCESS,
10+
CheckResult,
11+
CheckStatus,
12+
)
713

814
from sentry.issues.issue_occurrence import IssueEvidence, IssueOccurrence
915
from sentry.testutils.cases import TestCase, UptimeTestCase
@@ -217,6 +223,41 @@ def test_issue_creation_disabled(self):
217223
)
218224
assert evaluation is None
219225

226+
def test_flapping_evaluate(self):
227+
"""
228+
Test that a uptime monitor that flaps between failure, success success,
229+
failure, etc does not produce any evaluations.
230+
"""
231+
project_subscription = self.create_project_uptime_subscription()
232+
uptime_subscription = project_subscription.uptime_subscription
233+
detector = get_detector(project_subscription.uptime_subscription)
234+
assert detector
235+
236+
assert uptime_subscription.uptime_status == UptimeStatus.OK
237+
238+
now = datetime.now()
239+
240+
features = [
241+
"organizations:uptime-create-issues",
242+
"organizations:uptime-detector-create-issues",
243+
]
244+
245+
with (
246+
self.feature(features),
247+
mock.patch("sentry.uptime.grouptype.get_active_failure_threshold", return_value=3),
248+
):
249+
status_cycle: cycle[CheckStatus] = cycle(
250+
[CHECKSTATUS_FAILURE, CHECKSTATUS_SUCCESS, CHECKSTATUS_SUCCESS]
251+
)
252+
253+
for idx in range(12, 0, -1):
254+
result = self.create_uptime_result(
255+
status=next(status_cycle),
256+
scheduled_check_time=now - timedelta(minutes=idx),
257+
)
258+
evaluation = self.handle_result(detector, uptime_subscription, result)
259+
assert evaluation is None
260+
220261

221262
class TestUptimeDomainCheckFailureDetectorConfig(TestCase):
222263
def setUp(self):

0 commit comments

Comments
 (0)