22
22
23
23
from sentry .conf .types import kafka_definition
24
24
from sentry .conf .types .uptime import UptimeRegionConfig
25
- from sentry .constants import DataCategory , ObjectStatus
25
+ from sentry .constants import DataCategory
26
26
from sentry .models .group import Group , GroupStatus
27
27
from sentry .testutils .abstract import Abstract
28
28
from sentry .testutils .helpers .datetime import freeze_time
@@ -157,6 +157,25 @@ def test(self):
157
157
assert self .project_subscription .uptime_status == UptimeStatus .FAILED
158
158
assert self .project_subscription .uptime_subscription .uptime_status == UptimeStatus .FAILED
159
159
160
+ def test_does_nothing_when_missing_project_subscription (self ):
161
+ self .project_subscription .delete ()
162
+
163
+ result = self .create_uptime_result (
164
+ self .subscription .subscription_id ,
165
+ scheduled_check_time = datetime .now () - timedelta (minutes = 5 ),
166
+ )
167
+ with (
168
+ self .feature (["organizations:uptime" , "organizations:uptime-create-issues" ]),
169
+ mock .patch ("sentry.remote_subscriptions.consumers.result_consumer.logger" ) as logger ,
170
+ mock .patch (
171
+ "sentry.uptime.consumers.results_consumer.remove_uptime_subscription_if_unused"
172
+ ) as mock_remove_uptime_subscription_if_unused ,
173
+ ):
174
+ # Does not produce an error
175
+ self .send_result (result )
176
+ assert not logger .exception .called
177
+ mock_remove_uptime_subscription_if_unused .assert_called_with (self .subscription )
178
+
160
179
def test_restricted_host_provider_id (self ):
161
180
"""
162
181
Test that we do NOT create an issue when the host provider identifier
@@ -446,32 +465,6 @@ def test_no_subscription(self):
446
465
"default" , UptimeSubscription (subscription_id = subscription_id ), "delete" , None
447
466
)
448
467
449
- def test_multiple_project_subscriptions_with_disabled (self ):
450
- """
451
- Tests that we do not process results for disabled project subscriptions
452
- """
453
- # Second disabled project subscription
454
- self .create_project_uptime_subscription (
455
- uptime_subscription = self .subscription ,
456
- project = self .create_project (),
457
- status = ObjectStatus .DISABLED ,
458
- )
459
- result = self .create_uptime_result (self .subscription .subscription_id )
460
-
461
- with (
462
- mock .patch ("sentry.uptime.consumers.results_consumer.metrics" ) as metrics ,
463
- self .feature (["organizations:uptime" , "organizations:uptime-create-issues" ]),
464
- ):
465
- self .send_result (result )
466
- # We only process a single project result, the other is dropped,
467
- # there should be only one handle_result_for_project metric call
468
- handle_result_calls = [
469
- c
470
- for c in metrics .incr .mock_calls
471
- if c [1 ][0 ] == "uptime.result_processor.handle_result_for_project"
472
- ]
473
- assert len (handle_result_calls ) == 1
474
-
475
468
def test_organization_feature_disabled (self ):
476
469
"""
477
470
Tests that we do not process results for disabled project subscriptions
@@ -1063,6 +1056,7 @@ def test_check_and_update_regions(self):
1063
1056
subscription_id = uuid .UUID (int = 5 ).hex ,
1064
1057
region_slugs = ["region1" ],
1065
1058
)
1059
+ self .create_project_uptime_subscription (uptime_subscription = sub )
1066
1060
self .run_check_and_update_region_test (
1067
1061
sub ,
1068
1062
["region1" , "region2" ],
@@ -1093,6 +1087,7 @@ def test_check_and_update_regions_active_shadow(self):
1093
1087
subscription_id = uuid .UUID (int = 5 ).hex ,
1094
1088
region_slugs = ["region1" , "region2" ],
1095
1089
)
1090
+ self .create_project_uptime_subscription (uptime_subscription = sub )
1096
1091
self .run_check_and_update_region_test (
1097
1092
sub ,
1098
1093
["region1" , "region2" ],
@@ -1119,6 +1114,7 @@ def test_check_and_update_regions_larger_interval(self):
1119
1114
region_slugs = ["region1" ],
1120
1115
interval_seconds = UptimeSubscription .IntervalSeconds .ONE_HOUR ,
1121
1116
)
1117
+ self .create_project_uptime_subscription (uptime_subscription = hour_sub )
1122
1118
self .run_check_and_update_region_test (
1123
1119
hour_sub ,
1124
1120
["region1" , "region2" ],
@@ -1140,6 +1136,7 @@ def test_check_and_update_regions_larger_interval(self):
1140
1136
region_slugs = ["region1" ],
1141
1137
interval_seconds = UptimeSubscription .IntervalSeconds .FIVE_MINUTES ,
1142
1138
)
1139
+ self .create_project_uptime_subscription (uptime_subscription = five_min_sub )
1143
1140
self .run_check_and_update_region_test (
1144
1141
five_min_sub ,
1145
1142
["region1" , "region2" ],
@@ -1188,6 +1185,7 @@ def test_check_and_update_regions_larger_interval(self):
1188
1185
region_slugs = ["region1" ],
1189
1186
interval_seconds = UptimeSubscription .IntervalSeconds .FIVE_MINUTES ,
1190
1187
)
1188
+ self .create_project_uptime_subscription (uptime_subscription = five_min_sub )
1191
1189
self .run_check_and_update_region_test (
1192
1190
five_min_sub ,
1193
1191
["region1" , "region2" ],
@@ -1206,8 +1204,10 @@ def test_check_and_update_regions_larger_interval(self):
1206
1204
1207
1205
def test_check_and_update_regions_removes_disabled (self ):
1208
1206
sub = self .create_uptime_subscription (
1209
- subscription_id = uuid .UUID (int = 5 ).hex , region_slugs = ["region1" , "region2" ]
1207
+ subscription_id = uuid .UUID (int = 5 ).hex ,
1208
+ region_slugs = ["region1" , "region2" ],
1210
1209
)
1210
+ self .create_project_uptime_subscription (uptime_subscription = sub )
1211
1211
self .run_check_and_update_region_test (
1212
1212
sub ,
1213
1213
["region1" , "region2" ],
@@ -1259,6 +1259,7 @@ def test_parallel(self) -> None:
1259
1259
subscription_2 = self .create_uptime_subscription (
1260
1260
subscription_id = uuid .uuid4 ().hex , interval_seconds = 300 , url = "http://santry.io"
1261
1261
)
1262
+ self .create_project_uptime_subscription (uptime_subscription = subscription_2 )
1262
1263
1263
1264
result_1 = self .create_uptime_result (
1264
1265
self .subscription .subscription_id ,
@@ -1310,6 +1311,7 @@ def test_parallel_grouping(self, mock_process_group) -> None:
1310
1311
subscription_2 = self .create_uptime_subscription (
1311
1312
subscription_id = uuid .uuid4 ().hex , interval_seconds = 300 , url = "http://santry.io"
1312
1313
)
1314
+ self .create_project_uptime_subscription (uptime_subscription = subscription_2 )
1313
1315
1314
1316
result_1 = self .create_uptime_result (
1315
1317
self .subscription .subscription_id ,
0 commit comments