|
10 | 10 |
|
11 | 11 | from sentry import deletions, nodestore |
12 | 12 | from sentry.deletions.tasks.groups import delete_groups_for_project |
13 | | -from sentry.issues.grouptype import GroupCategory |
| 13 | +from sentry.issues.grouptype import FeedbackGroup, GroupCategory |
14 | 14 | from sentry.issues.issue_occurrence import IssueOccurrence |
15 | 15 | from sentry.models.eventattachment import EventAttachment |
16 | 16 | from sentry.models.group import Group |
@@ -383,6 +383,61 @@ def select_rows( |
383 | 383 | def tenant_ids(self) -> dict[str, str]: |
384 | 384 | return {"referrer": self.referrer, "organization_id": self.organization.id} |
385 | 385 |
|
| 386 | + def test_simple_issue_platform(self) -> None: |
| 387 | + # Adding this query here to make sure that the cache is not being used |
| 388 | + assert self.select_error_events(self.project.id) is None |
| 389 | + assert self.select_issue_platform_events(self.project.id) is None |
| 390 | + |
| 391 | + # Create initial error event and occurrence related to it; two different groups will exist |
| 392 | + event = self.store_event(data={}, project_id=self.project.id) |
| 393 | + # XXX: We need a different way of creating occurrences which will insert into the nodestore |
| 394 | + occurrence_event, issue_platform_group = self.create_occurrence( |
| 395 | + event, type_id=FeedbackGroup.type_id |
| 396 | + ) |
| 397 | + |
| 398 | + # Assertions after creation |
| 399 | + assert occurrence_event.id != event.event_id |
| 400 | + assert event.group_id != issue_platform_group.id |
| 401 | + assert event.group.issue_category == GroupCategory.ERROR |
| 402 | + assert issue_platform_group.issue_category == GroupCategory.FEEDBACK |
| 403 | + assert issue_platform_group.type == FeedbackGroup.type_id |
| 404 | + |
| 405 | + # Assert that the error event has been inserted in the nodestore & Snuba |
| 406 | + event_node_id = Event.generate_node_id(event.project_id, event.event_id) |
| 407 | + assert nodestore.backend.get(event_node_id) |
| 408 | + expected_error = {"event_id": event.event_id, "group_id": event.group_id} |
| 409 | + assert self.select_error_events(self.project.id) == expected_error |
| 410 | + |
| 411 | + # Assert that the occurrence event has been inserted in the nodestore & Snuba |
| 412 | + # occurrence_node_id = Event.generate_node_id( |
| 413 | + # occurrence_event.project_id, occurrence_event.id |
| 414 | + # ) |
| 415 | + # assert nodestore.backend.get(occurrence_node_id) |
| 416 | + expected_occurrence_event = { |
| 417 | + "event_id": occurrence_event.event_id, |
| 418 | + "group_id": issue_platform_group.id, |
| 419 | + "occurrence_id": occurrence_event.id, |
| 420 | + } |
| 421 | + assert self.select_issue_platform_events(self.project.id) == expected_occurrence_event |
| 422 | + |
| 423 | + # This will delete the group and the events from the node store and Snuba |
| 424 | + with self.tasks(): |
| 425 | + delete_groups_for_project( |
| 426 | + object_ids=[issue_platform_group.id], |
| 427 | + transaction_id=uuid4().hex, |
| 428 | + project_id=self.project.id, |
| 429 | + ) |
| 430 | + |
| 431 | + # The original error event and group still exist |
| 432 | + assert Group.objects.filter(id=event.group_id).exists() |
| 433 | + assert nodestore.backend.get(event_node_id) |
| 434 | + assert self.select_error_events(self.project.id) == expected_error |
| 435 | + |
| 436 | + # The Issue Platform group and occurrence have been deleted |
| 437 | + assert not Group.objects.filter(id=issue_platform_group.id).exists() |
| 438 | + # assert not nodestore.backend.get(occurrence_node_id) |
| 439 | + assert self.select_issue_platform_events(self.project.id) is None |
| 440 | + |
386 | 441 | @mock.patch("sentry.deletions.tasks.nodestore.bulk_snuba_queries") |
387 | 442 | def test_issue_platform_batching(self, mock_bulk_snuba_queries: mock.Mock) -> None: |
388 | 443 | # Patch max_rows_to_delete to a small value for testing |
|
0 commit comments