Skip to content

Commit 9a12aae

Browse files
committed
test(deletions): add issue platform group deletion test back
1 parent 3d7a9cd commit 9a12aae

File tree

1 file changed

+60
-5
lines changed

1 file changed

+60
-5
lines changed

tests/sentry/deletions/test_group.py

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from sentry import deletions, nodestore
1212
from sentry.deletions.defaults.group import update_group_hash_metadata_in_batches
1313
from sentry.deletions.tasks.groups import delete_groups_for_project
14-
from sentry.issues.grouptype import GroupCategory
14+
from sentry.issues.grouptype import FeedbackGroup, GroupCategory
1515
from sentry.issues.issue_occurrence import IssueOccurrence
1616
from sentry.models.activity import Activity
1717
from sentry.models.eventattachment import EventAttachment
@@ -441,6 +441,61 @@ def select_rows(
441441
def tenant_ids(self) -> dict[str, str]:
442442
return {"referrer": self.referrer, "organization_id": self.organization.id}
443443

444+
def test_simple_issue_platform(self) -> None:
445+
# Adding this query here to make sure that the cache is not being used
446+
assert self.select_error_events(self.project.id) is None
447+
assert self.select_issue_platform_events(self.project.id) is None
448+
449+
# Create initial error event and occurrence related to it; two different groups will exist
450+
event = self.store_event(data={}, project_id=self.project.id)
451+
# XXX: We need a different way of creating occurrences which will insert into the nodestore
452+
occurrence_event, issue_platform_group = self.create_occurrence(
453+
event, type_id=FeedbackGroup.type_id
454+
)
455+
456+
# Assertions after creation
457+
assert occurrence_event.id != event.event_id
458+
assert event.group_id != issue_platform_group.id
459+
assert event.group.issue_category == GroupCategory.ERROR
460+
assert issue_platform_group.issue_category == GroupCategory.FEEDBACK
461+
assert issue_platform_group.type == FeedbackGroup.type_id
462+
463+
# Assert that the error event has been inserted in the nodestore & Snuba
464+
event_node_id = Event.generate_node_id(event.project_id, event.event_id)
465+
assert nodestore.backend.get(event_node_id)
466+
expected_error = {"event_id": event.event_id, "group_id": event.group_id}
467+
assert self.select_error_events(self.project.id) == expected_error
468+
469+
# Assert that the occurrence event has been inserted in the nodestore & Snuba
470+
# occurrence_node_id = Event.generate_node_id(
471+
# occurrence_event.project_id, occurrence_event.id
472+
# )
473+
# assert nodestore.backend.get(occurrence_node_id)
474+
expected_occurrence_event = {
475+
"event_id": occurrence_event.event_id,
476+
"group_id": issue_platform_group.id,
477+
"occurrence_id": occurrence_event.id,
478+
}
479+
assert self.select_issue_platform_events(self.project.id) == expected_occurrence_event
480+
481+
# This will delete the group and the events from the node store and Snuba
482+
with self.tasks():
483+
delete_groups_for_project(
484+
object_ids=[issue_platform_group.id],
485+
transaction_id=uuid4().hex,
486+
project_id=self.project.id,
487+
)
488+
489+
# The original error event and group still exist
490+
assert Group.objects.filter(id=event.group_id).exists()
491+
assert nodestore.backend.get(event_node_id)
492+
assert self.select_error_events(self.project.id) == expected_error
493+
494+
# The Issue Platform group and occurrence have been deleted
495+
assert not Group.objects.filter(id=issue_platform_group.id).exists()
496+
# assert not nodestore.backend.get(occurrence_node_id)
497+
assert self.select_issue_platform_events(self.project.id) is None
498+
444499
@mock.patch("sentry.deletions.tasks.nodestore.bulk_snuba_queries")
445500
def test_issue_platform_batching(self, mock_bulk_snuba_queries: mock.Mock) -> None:
446501
# Patch max_rows_to_delete to a small value for testing
@@ -455,10 +510,10 @@ def test_issue_platform_batching(self, mock_bulk_snuba_queries: mock.Mock) -> No
455510
group4 = self.create_group(project=self.project)
456511

457512
# Set times_seen for each group
458-
Group.objects.filter(id=group1.id).update(times_seen=3, type=GroupCategory.FEEDBACK)
459-
Group.objects.filter(id=group2.id).update(times_seen=1, type=GroupCategory.FEEDBACK)
460-
Group.objects.filter(id=group3.id).update(times_seen=3, type=GroupCategory.FEEDBACK)
461-
Group.objects.filter(id=group4.id).update(times_seen=3, type=GroupCategory.FEEDBACK)
513+
Group.objects.filter(id=group1.id).update(times_seen=3, type=FeedbackGroup.type_id)
514+
Group.objects.filter(id=group2.id).update(times_seen=1, type=FeedbackGroup.type_id)
515+
Group.objects.filter(id=group3.id).update(times_seen=3, type=FeedbackGroup.type_id)
516+
Group.objects.filter(id=group4.id).update(times_seen=3, type=FeedbackGroup.type_id)
462517

463518
# This will delete the group and the events from the node store and Snuba
464519
with self.tasks():

0 commit comments

Comments
 (0)