test_performance_trends.py 2.7 KB

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