|
6 | 6 | from datetime import UTC, datetime, timedelta |
7 | 7 | from time import sleep |
8 | 8 | from typing import Any |
| 9 | +from unittest import mock |
9 | 10 | from unittest.mock import MagicMock, Mock, call, patch |
10 | 11 | from uuid import uuid4 |
11 | 12 |
|
|
23 | 24 | from sentry.integrations.models.organization_integration import OrganizationIntegration |
24 | 25 | from sentry.issues.grouptype import ( |
25 | 26 | FeedbackGroup, |
| 27 | + NoiseConfig, |
26 | 28 | PerformanceNPlusOneGroupType, |
27 | 29 | PerformanceSlowDBQueryGroupType, |
28 | 30 | ) |
| 31 | +from sentry.issues.ingest import save_issue_occurrence |
29 | 32 | from sentry.models.activity import Activity |
30 | 33 | from sentry.models.apitoken import ApiToken |
31 | 34 | from sentry.models.eventattachment import EventAttachment |
@@ -500,39 +503,61 @@ def test_auto_resolved(self) -> None: |
500 | 503 | assert response.data[0]["id"] == str(group2.id) |
501 | 504 |
|
502 | 505 | def test_perf_issue(self) -> None: |
503 | | - perf_group = self.create_group(type=PerformanceNPlusOneGroupType.type_id) |
504 | | - self.login_as(user=self.user) |
505 | | - with self.feature( |
506 | | - { |
507 | | - "organizations:issue-search-allow-postgres-only-search": True, |
508 | | - } |
| 506 | + event = self.store_event( |
| 507 | + data={ |
| 508 | + "timestamp": before_now(seconds=1).isoformat(), |
| 509 | + }, |
| 510 | + project_id=self.project.id, |
| 511 | + ) |
| 512 | + occurrence = self.build_occurrence( |
| 513 | + event_id=event.event_id, |
| 514 | + fingerprint=["perf-issue-occurrence"], |
| 515 | + type=PerformanceNPlusOneGroupType.type_id, |
| 516 | + project_id=self.project.id, |
| 517 | + ) |
| 518 | + with mock.patch.object( |
| 519 | + PerformanceNPlusOneGroupType, |
| 520 | + "noise_config", |
| 521 | + new=NoiseConfig(0, timedelta(minutes=1)), |
509 | 522 | ): |
510 | | - response = self.get_success_response(query="issue.category:performance") |
511 | | - assert len(response.data) == 1 |
512 | | - assert response.data[0]["id"] == str(perf_group.id) |
| 523 | + saved_occurrence, group_info = save_issue_occurrence(occurrence.to_dict(), event) |
| 524 | + assert group_info is not None |
| 525 | + perf_group = group_info.group |
| 526 | + self.login_as(user=self.user) |
| 527 | + response = self.get_success_response(query="issue.category:performance") |
| 528 | + assert len(response.data) == 1 |
| 529 | + assert response.data[0]["id"] == str(perf_group.id) |
513 | 530 |
|
514 | 531 | def test_has_seer_last_run(self) -> None: |
515 | 532 | """Test filtering issues by whether they have seer_autofix_last_triggered set.""" |
516 | | - # Create two groups - one with seer_autofix_last_triggered and one without |
517 | | - group_with_seer = self.create_group() |
| 533 | + event1 = self.store_event( |
| 534 | + data={ |
| 535 | + "fingerprint": ["seer-group"], |
| 536 | + "timestamp": before_now(seconds=1).isoformat(), |
| 537 | + }, |
| 538 | + project_id=self.project.id, |
| 539 | + ) |
| 540 | + group_with_seer = event1.group |
518 | 541 | group_with_seer.update(seer_autofix_last_triggered=timezone.now()) |
519 | | - group_without_seer = self.create_group() |
| 542 | + event2 = self.store_event( |
| 543 | + data={ |
| 544 | + "fingerprint": ["no-seer-group"], |
| 545 | + "timestamp": before_now(seconds=1).isoformat(), |
| 546 | + }, |
| 547 | + project_id=self.project.id, |
| 548 | + ) |
| 549 | + group_without_seer = event2.group |
520 | 550 |
|
521 | 551 | self.login_as(user=self.user) |
522 | | - with self.feature( |
523 | | - { |
524 | | - "organizations:issue-search-allow-postgres-only-search": True, |
525 | | - } |
526 | | - ): |
527 | | - # Query for issues that have seer_autofix_last_triggered set |
528 | | - response = self.get_success_response(query="has:issue.seer_last_run") |
529 | | - assert len(response.data) == 1 |
530 | | - assert response.data[0]["id"] == str(group_with_seer.id) |
| 552 | + # Query for issues that have seer_autofix_last_triggered set |
| 553 | + response = self.get_success_response(query="has:issue.seer_last_run") |
| 554 | + assert len(response.data) == 1 |
| 555 | + assert response.data[0]["id"] == str(group_with_seer.id) |
531 | 556 |
|
532 | | - # Query for issues that do NOT have seer_autofix_last_triggered set |
533 | | - response = self.get_success_response(query="!has:issue.seer_last_run") |
534 | | - assert len(response.data) == 1 |
535 | | - assert response.data[0]["id"] == str(group_without_seer.id) |
| 557 | + # Query for issues that do NOT have seer_autofix_last_triggered set |
| 558 | + response = self.get_success_response(query="!has:issue.seer_last_run") |
| 559 | + assert len(response.data) == 1 |
| 560 | + assert response.data[0]["id"] == str(group_without_seer.id) |
536 | 561 |
|
537 | 562 | def test_lookup_by_event_id(self) -> None: |
538 | 563 | project = self.project |
|
0 commit comments