test_group.py 3.2 KB

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