Browse Source

test(perf-issues): Unflakefy performance issues acceptance test (#40742)

Closes PERF-1785, unskips https://github.com/getsentry/sentry/pull/40722

- Use a stable event ID
- Set a stable trace context
- Introduce consistent timestamps
George Gritsouk 2 years ago
parent
commit
37d34f2221
1 changed files with 24 additions and 14 deletions
  1. 24 14
      tests/acceptance/test_performance_issues.py

+ 24 - 14
tests/acceptance/test_performance_issues.py

@@ -1,17 +1,14 @@
-import datetime
+from datetime import datetime, timedelta
 from unittest.mock import patch
 
-import pytest
 import pytz
 
 from fixtures.page_objects.issue_details import IssueDetailsPage
 from sentry import options
 from sentry.testutils import AcceptanceTestCase, SnubaTestCase
 from sentry.utils import json
-from sentry.utils.samples import load_data
 
 
-@pytest.mark.skip(reason="PERF-1785: flaky: inconsistent snapshot")
 class PerformanceIssuesTest(AcceptanceTestCase, SnubaTestCase):
     def setUp(self):
         super().setUp()
@@ -29,18 +26,30 @@ class PerformanceIssuesTest(AcceptanceTestCase, SnubaTestCase):
         self.page = IssueDetailsPage(self.browser, self.client)
         self.dismiss_assistant()
 
-    @patch("django.utils.timezone.now")
-    def test_with_one_performance_issue(self, mock_now):
-        event = load_data("transaction")
-
-        data = json.loads(
+    def create_sample_event(self, start_timestamp):
+        event = json.loads(
             self.load_fixture("events/performance_problems/n-plus-one-in-django-new-view.json")
         )
-        event.update({"spans": data["spans"]})
 
-        mock_now.return_value = datetime.datetime.fromtimestamp(event["start_timestamp"]).replace(
-            tzinfo=pytz.utc
-        )
+        for key in ["datetime", "location", "title"]:
+            del event[key]
+
+        event["contexts"] = {
+            "trace": {"trace_id": "530c14e044aa464db6ddb43660e6474f", "span_id": "139fcdb7c5534eb4"}
+        }
+
+        ms_delta = start_timestamp - event["start_timestamp"]
+
+        for item in [event, *event["spans"]]:
+            item["start_timestamp"] += ms_delta
+            item["timestamp"] += ms_delta
+
+        return event
+
+    @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(
             [
@@ -49,7 +58,8 @@ class PerformanceIssuesTest(AcceptanceTestCase, SnubaTestCase):
                 "organizations:performance-issues-ingest",
             ]
         ):
-            event = self.store_event(data=event, project_id=self.project.id)
+            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"]')