test_performance_trends.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. from datetime import timezone
  2. from unittest.mock import patch
  3. from urllib.parse import urlencode
  4. from django.db.models import F
  5. from fixtures.page_objects.base import BasePage
  6. from sentry.models import Project
  7. from sentry.testutils.cases import AcceptanceTestCase, SnubaTestCase
  8. from sentry.testutils.helpers.datetime import before_now, iso_format
  9. from sentry.testutils.silo import no_silo_test
  10. from sentry.utils.samples import load_data
  11. @no_silo_test(stable=True)
  12. class PerformanceTrendsTest(AcceptanceTestCase, SnubaTestCase):
  13. def make_trend(
  14. self,
  15. name,
  16. durations,
  17. period_mins=60,
  18. ):
  19. for index, duration in enumerate(durations):
  20. time_between = period_mins / len(durations)
  21. # distirbute events over the period
  22. minutes = period_mins - ((index + 1) * time_between) + (time_between / 2)
  23. event = load_data("transaction")
  24. event.update(
  25. {
  26. "transaction": name,
  27. "event_id": f"{index:02x}".rjust(32, "0"),
  28. "start_timestamp": iso_format(before_now(minutes=minutes, seconds=duration)),
  29. "timestamp": iso_format(before_now(minutes=minutes)),
  30. }
  31. )
  32. self.store_event(data=event, project_id=self.project.id)
  33. def setUp(self):
  34. super().setUp()
  35. self.org = self.create_organization(owner=self.user, name="Rowdy Tiger")
  36. self.team = self.create_team(
  37. organization=self.org, name="Mariachi Band", members=[self.user]
  38. )
  39. self.project = self.create_project(organization=self.org, teams=[self.team], name="Bengal")
  40. self.group = self.create_group(project=self.project)
  41. self.login_as(self.user)
  42. self.path = "/organizations/{}/performance/trends/?{}".format(
  43. self.org.slug,
  44. urlencode(
  45. {
  46. "query": "transaction.duration:>0",
  47. "statsPeriod": "1h",
  48. "project": self.project.id,
  49. }
  50. ),
  51. )
  52. self.page = BasePage(self.browser)
  53. @patch("django.utils.timezone.now")
  54. def test_with_data(self, mock_now):
  55. mock_now.return_value = before_now().replace(tzinfo=timezone.utc)
  56. values = range(1, 100, 5)
  57. self.make_trend("improvement", [v for v in reversed(values)])
  58. self.make_trend("regression", values)
  59. self.project.update(flags=F("flags").bitor(Project.flags.has_transactions))
  60. with self.feature("organizations:performance-view"):
  61. self.browser.get(self.path)
  62. self.page.wait_until_loaded()
  63. trend_item = '[data-test-id="trends-list-item-regression"]'
  64. self.browser.wait_until(trend_item)
  65. self.browser.snapshot("performance trends - with data")