Skip to content

Commit 2a0df0c

Browse files
authored
ref(grouping): Rewrite hierarchical grouping tests (#74144)
This makes the tests a little easier to understand and prepares for my next set of changes.
1 parent 2a3aacf commit 2a0df0c

File tree

1 file changed

+56
-90
lines changed

1 file changed

+56
-90
lines changed

tests/sentry/event_manager/test_hierarchical_hashes.py

+56-90
Original file line numberDiff line numberDiff line change
@@ -202,54 +202,19 @@ def test_partial_move(default_project, fast_save):
202202

203203

204204
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
241207

242-
event = save_event(0)
208+
event = self.save_event()
243209

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")
247211

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()
250214

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
252216
assert not set(event.get_hashes().hashes) & set(event2.get_hashes().hashes)
217+
# They are both grouped together
253218
assert event.group_id == event2.group_id
254219

255220
group = Group.objects.get(id=event.group_id)
@@ -258,58 +223,23 @@ def save_event(ts_offset):
258223
assert group.last_seen == event2.datetime
259224

260225
# 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()
263228
assert event3.group_id == event2.group_id
264229

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
301232

302-
event = save_event(0)
233+
event = self.save_event()
303234

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")
307236

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()
310239

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
312241
assert not set(event.get_hashes().hashes) & set(event2.get_hashes().hashes)
242+
# They are both grouped together
313243
assert event.group_id == event2.group_id
314244

315245
group = Group.objects.get(id=event.group_id)
@@ -325,6 +255,42 @@ def save_event(ts_offset):
325255
assert group.last_seen == event2.datetime
326256

327257
# 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()
330260
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

Comments
 (0)