Browse Source

test(perf-issues): Add more E2E tests (#40723)

- one test verifies that similar events are grouped
- one test verifies that dissimilar events are not grouped
George Gritsouk 2 years ago
parent
commit
8d05e775c1
1 changed files with 43 additions and 7 deletions
  1. 43 7
      tests/acceptance/test_performance_issues.py

+ 43 - 7
tests/acceptance/test_performance_issues.py

@@ -1,3 +1,5 @@
+import random
+import string
 from datetime import datetime, timedelta
 from unittest.mock import patch
 
@@ -5,9 +7,16 @@ import pytz
 
 from fixtures.page_objects.issue_details import IssueDetailsPage
 from sentry import options
+from sentry.models import Group
 from sentry.testutils import AcceptanceTestCase, SnubaTestCase
 from sentry.utils import json
 
+FEATURES = {
+    "projects:performance-suspect-spans-ingestion": True,
+    "organizations:performance-issues": True,
+    "organizations:performance-issues-ingest": True,
+}
+
 
 class PerformanceIssuesTest(AcceptanceTestCase, SnubaTestCase):
     def setUp(self):
@@ -46,21 +55,48 @@ class PerformanceIssuesTest(AcceptanceTestCase, SnubaTestCase):
 
         return event
 
+    def randomize_span_description(self, span):
+        return {
+            **span,
+            "description": "".join(random.choice(string.ascii_lowercase) for _ in range(10)),
+        }
+
     @patch("django.utils.timezone.now")
     def test_with_one_performance_issue(self, mock_now):
         mock_now.return_value = datetime.utcnow().replace(tzinfo=pytz.utc) - timedelta(minutes=5)
         event_data = self.create_sample_event(mock_now.return_value.timestamp())
 
-        with self.feature(
-            [
-                "projects:performance-suspect-spans-ingestion",
-                "organizations:performance-issues",
-                "organizations:performance-issues-ingest",
-            ]
-        ):
+        with self.feature(FEATURES):
             event = self.store_event(data=event_data, project_id=self.project.id)
 
             self.page.visit_issue(self.org.slug, event.groups[0].id)
             self.browser.click('[aria-label="Show Details"]')
 
             self.browser.snapshot("performance issue details", desktop_only=True)
+
+    @patch("django.utils.timezone.now")
+    def test_multiple_events_with_one_cause_are_grouped(self, mock_now):
+        mock_now.return_value = datetime.utcnow().replace(tzinfo=pytz.utc) - timedelta(minutes=5)
+        event_data = self.create_sample_event(mock_now.return_value.timestamp())
+
+        with self.feature(FEATURES):
+            [self.store_event(data=event_data, project_id=self.project.id) for _ in range(3)]
+
+            assert Group.objects.count() == 1
+
+    @patch("django.utils.timezone.now")
+    def test_multiple_events_with_multiple_causes_are_not_grouped(self, mock_now):
+        mock_now.return_value = datetime.utcnow().replace(tzinfo=pytz.utc) - timedelta(minutes=5)
+
+        # Create identical events with different parent spans
+        for _ in range(3):
+            event_data = self.create_sample_event(mock_now.return_value.timestamp())
+            event_data["spans"] = [
+                self.randomize_span_description(span) if span["op"] == "django.view" else span
+                for span in event_data["spans"]
+            ]
+
+            with self.feature(FEATURES):
+                self.store_event(data=event_data, project_id=self.project.id)
+
+        assert Group.objects.count() == 3