|
1 | 1 | from datetime import datetime, timedelta
|
| 2 | +from itertools import cycle |
2 | 3 | from unittest import mock
|
3 | 4 |
|
4 | 5 | import pytest
|
5 | 6 | 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 | +) |
7 | 13 |
|
8 | 14 | from sentry.issues.issue_occurrence import IssueEvidence, IssueOccurrence
|
9 | 15 | from sentry.testutils.cases import TestCase, UptimeTestCase
|
@@ -217,6 +223,41 @@ def test_issue_creation_disabled(self):
|
217 | 223 | )
|
218 | 224 | assert evaluation is None
|
219 | 225 |
|
| 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 | + |
220 | 261 |
|
221 | 262 | class TestUptimeDomainCheckFailureDetectorConfig(TestCase):
|
222 | 263 | def setUp(self):
|
|
0 commit comments