test_performance_trends.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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)