@@ -202,54 +202,19 @@ def test_partial_move(default_project, fast_save):
202
202
203
203
204
204
class EventManagerGroupingTest (TestCase ):
205
- def test_applies_secondary_grouping_hierarchical (self ):
206
- project = self .project
207
- project .update_option ("sentry:grouping_config" , "legacy:2019-03-12" )
208
- project .update_option ("sentry:secondary_grouping_expiry" , 0 )
209
-
210
- timestamp = time .time () - 300
211
-
212
- def save_event (ts_offset ):
213
- ts = timestamp + ts_offset
214
- manager = EventManager (
215
- make_event (
216
- message = "foo 123" ,
217
- event_id = hex (2 ** 127 + int (ts ))[- 32 :],
218
- timestamp = ts ,
219
- exception = {
220
- "values" : [
221
- {
222
- "type" : "Hello" ,
223
- "stacktrace" : {
224
- "frames" : [
225
- {
226
- "function" : "not_in_app_function" ,
227
- },
228
- {
229
- "function" : "in_app_function" ,
230
- },
231
- ]
232
- },
233
- }
234
- ]
235
- },
236
- )
237
- )
238
- manager .normalize ()
239
- with self .tasks ():
240
- return manager .save (project .id )
205
+ def test_can_upgrade_to_hierarchical_config (self ):
206
+ self .set_options ("legacy:2019-03-12" ) # Starting configuration
241
207
242
- event = save_event (0 )
208
+ event = self . save_event ()
243
209
244
- project .update_option ("sentry:grouping_config" , "mobile:2021-02-12" )
245
- project .update_option ("sentry:secondary_grouping_config" , "legacy:2019-03-12" )
246
- project .update_option ("sentry:secondary_grouping_expiry" , time .time () + (24 * 90 * 3600 ))
210
+ self .transition_to_new_config ("mobile:2021-02-12" )
247
211
248
- # Switching to newstyle grouping changes hashes as 123 will be removed
249
- event2 = save_event (2 )
212
+ # This event will have two sets of hashes
213
+ event2 = self . save_event ()
250
214
251
- # make sure that events did get into same group because of fallback grouping, not because of hashes which come from primary grouping only
215
+ # The hashes property between the two events do not intersect
252
216
assert not set (event .get_hashes ().hashes ) & set (event2 .get_hashes ().hashes )
217
+ # They are both grouped together
253
218
assert event .group_id == event2 .group_id
254
219
255
220
group = Group .objects .get (id = event .group_id )
@@ -258,58 +223,23 @@ def save_event(ts_offset):
258
223
assert group .last_seen == event2 .datetime
259
224
260
225
# After expiry, new events are still assigned to the same group:
261
- project .update_option ("sentry:secondary_grouping_expiry" , 0 )
262
- event3 = save_event (4 )
226
+ self . project .update_option ("sentry:secondary_grouping_expiry" , 0 )
227
+ event3 = self . save_event ()
263
228
assert event3 .group_id == event2 .group_id
264
229
265
- def test_applies_downgrade_hierarchical (self ):
266
- project = self .project
267
- project .update_option ("sentry:grouping_config" , "mobile:2021-02-12" )
268
- project .update_option ("sentry:secondary_grouping_expiry" , 0 )
269
-
270
- timestamp = time .time () - 300
271
-
272
- def save_event (ts_offset ):
273
- ts = timestamp + ts_offset
274
- manager = EventManager (
275
- make_event (
276
- message = "foo 123" ,
277
- event_id = hex (2 ** 127 + int (ts ))[- 32 :],
278
- timestamp = ts ,
279
- exception = {
280
- "values" : [
281
- {
282
- "type" : "Hello" ,
283
- "stacktrace" : {
284
- "frames" : [
285
- {
286
- "function" : "not_in_app_function" ,
287
- },
288
- {
289
- "function" : "in_app_function" ,
290
- },
291
- ]
292
- },
293
- }
294
- ]
295
- },
296
- )
297
- )
298
- manager .normalize ()
299
- with self .tasks ():
300
- return manager .save (project .id )
230
+ def test_can_downgrade_from_hierarchical_config (self ):
231
+ self .set_options ("mobile:2021-02-12" ) # Starting configuration
301
232
302
- event = save_event (0 )
233
+ event = self . save_event ()
303
234
304
- project .update_option ("sentry:grouping_config" , "legacy:2019-03-12" )
305
- project .update_option ("sentry:secondary_grouping_config" , "mobile:2021-02-12" )
306
- project .update_option ("sentry:secondary_grouping_expiry" , time .time () + (24 * 90 * 3600 ))
235
+ self .transition_to_new_config ("legacy:2019-03-12" )
307
236
308
- # Switching to newstyle grouping changes hashes as 123 will be removed
309
- event2 = save_event (2 )
237
+ # This event will have two sets of hashes
238
+ event2 = self . save_event ()
310
239
311
- # make sure that events did get into same group because of fallback grouping, not because of hashes which come from primary grouping only
240
+ # The hashes property between the two events do not intersect
312
241
assert not set (event .get_hashes ().hashes ) & set (event2 .get_hashes ().hashes )
242
+ # They are both grouped together
313
243
assert event .group_id == event2 .group_id
314
244
315
245
group = Group .objects .get (id = event .group_id )
@@ -325,6 +255,42 @@ def save_event(ts_offset):
325
255
assert group .last_seen == event2 .datetime
326
256
327
257
# After expiry, new events are still assigned to the same group:
328
- project .update_option ("sentry:secondary_grouping_expiry" , 0 )
329
- event3 = save_event (4 )
258
+ self . project .update_option ("sentry:secondary_grouping_expiry" , 0 )
259
+ event3 = self . save_event ()
330
260
assert event3 .group_id == event2 .group_id
261
+
262
+ def save_event (self ):
263
+ manager = EventManager (
264
+ make_event (
265
+ message = "foo 123" ,
266
+ event_id = hex (2 ** 127 )[- 32 :],
267
+ exception = {
268
+ "values" : [
269
+ {
270
+ "type" : "Hello" ,
271
+ "stacktrace" : {
272
+ "frames" : [
273
+ {"function" : "not_in_app_function" },
274
+ {"function" : "in_app_function" },
275
+ ]
276
+ },
277
+ }
278
+ ]
279
+ },
280
+ )
281
+ )
282
+ manager .normalize ()
283
+ with self .tasks ():
284
+ return manager .save (self .project .id )
285
+
286
+ def set_options (self , primary_config ):
287
+ self .project .update_option ("sentry:grouping_config" , primary_config )
288
+ self .project .update_option ("sentry:secondary_grouping_expiry" , 0 )
289
+
290
+ def transition_to_new_config (self , new_config ):
291
+ original_config = self .project .get_option ("sentry:grouping_config" )
292
+ self .project .update_option ("sentry:grouping_config" , new_config )
293
+ self .project .update_option ("sentry:secondary_grouping_config" , original_config )
294
+ self .project .update_option (
295
+ "sentry:secondary_grouping_expiry" , time .time () + (24 * 90 * 3600 )
296
+ )
0 commit comments