test_performance_trends.py 2.7 KB

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