test_group.py 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. from sentry.issues.grouptype import PerformanceNPlusOneGroupType
  2. from sentry.models import Group
  3. from sentry.testutils import SnubaTestCase, TestCase
  4. from sentry.testutils.cases import PerformanceIssueTestCase
  5. from sentry.testutils.helpers.datetime import before_now, iso_format
  6. from sentry.testutils.silo import region_silo_test
  7. from sentry.utils.samples import load_data
  8. @region_silo_test
  9. class GroupTestSnuba(TestCase, SnubaTestCase, PerformanceIssueTestCase):
  10. def test_get_oldest_latest_for_environments(self):
  11. project = self.create_project()
  12. min_ago = iso_format(before_now(minutes=1))
  13. self.store_event(
  14. data={
  15. "event_id": "a" * 32,
  16. "environment": "production",
  17. "timestamp": min_ago,
  18. "fingerprint": ["group-1"],
  19. },
  20. project_id=project.id,
  21. )
  22. self.store_event(
  23. data={
  24. "event_id": "b" * 32,
  25. "environment": "production",
  26. "timestamp": min_ago,
  27. "fingerprint": ["group-1"],
  28. },
  29. project_id=project.id,
  30. )
  31. self.store_event(
  32. data={"event_id": "c" * 32, "timestamp": min_ago, "fingerprint": ["group-1"]},
  33. project_id=project.id,
  34. )
  35. group = Group.objects.first()
  36. assert group.get_latest_event_for_environments().event_id == "c" * 32
  37. assert group.get_latest_event_for_environments(["staging"]) is None
  38. assert group.get_latest_event_for_environments(["production"]).event_id == "b" * 32
  39. assert group.get_oldest_event_for_environments().event_id == "a" * 32
  40. assert (
  41. group.get_oldest_event_for_environments(["staging", "production"]).event_id == "a" * 32
  42. )
  43. assert group.get_oldest_event_for_environments(["staging"]) is None
  44. def test_perf_issue(self):
  45. group_fingerprint = f"{PerformanceNPlusOneGroupType.type_id}-group1"
  46. event_data_1 = load_data("transaction-n-plus-one", fingerprint=[group_fingerprint])
  47. event_data_1["timestamp"] = iso_format(before_now(seconds=10))
  48. event_data_1["start_timestamp"] = iso_format(before_now(seconds=11))
  49. event_data_1["event_id"] = "d" * 32
  50. event_data_2 = load_data("transaction-n-plus-one", fingerprint=[group_fingerprint])
  51. event_data_2["timestamp"] = iso_format(before_now(seconds=20))
  52. event_data_2["start_timestamp"] = iso_format(before_now(seconds=21))
  53. event_data_2["event_id"] = "f" * 32
  54. event_data_3 = load_data("transaction-n-plus-one", fingerprint=[group_fingerprint])
  55. event_data_3["timestamp"] = iso_format(before_now(seconds=30))
  56. event_data_3["start_timestamp"] = iso_format(before_now(seconds=31))
  57. event_data_3["event_id"] = "f" * 32
  58. transaction_event_1 = self.create_performance_issue(
  59. event_data=event_data_1, fingerprint=group_fingerprint
  60. )
  61. self.create_performance_issue(event_data=event_data_2, fingerprint=group_fingerprint)
  62. self.create_performance_issue(event_data=event_data_3, fingerprint=group_fingerprint)
  63. perf_group = transaction_event_1.group
  64. assert perf_group.get_latest_event_for_environments().event_id == "d" * 32
  65. assert perf_group.get_oldest_event_for_environments().event_id == "f" * 32