Browse Source

test(issue-platform): add test to verify group_on_time rollups when querying tsdb (#43158)

Make sure the rollup/granularities we're passing in correctly group on
the correct time buckets.
Gilbert Szeto 2 years ago
parent
commit
2d623a43db
1 changed files with 43 additions and 1 deletions
  1. 43 1
      tests/snuba/tsdb/test_tsdb_backend.py

+ 43 - 1
tests/snuba/tsdb/test_tsdb_backend.py

@@ -1,4 +1,4 @@
-from datetime import datetime, timedelta
+from datetime import datetime, timedelta, timezone
 from unittest.mock import patch
 
 import pytz
@@ -778,6 +778,48 @@ class SnubaTSDBGroupProfilingTest(TestCase, SnubaTestCase, SearchIssueTestMixin)
         self.proj1group2 = all_groups[1]
         self.defaultenv = Environment.objects.get(name=defaultenv)
 
+    def test_range_group_manual_group_time_rollup(self):
+        project = self.create_project()
+
+        # these are the only granularities/rollups that be actually be used
+        GRANULARITIES = [
+            (10, timedelta(seconds=10), 5),
+            (60 * 60, timedelta(hours=1), 6),
+            (60 * 60 * 24, timedelta(days=1), 15),
+        ]
+
+        start = (datetime.now(timezone.utc) - timedelta(days=15)).replace(
+            hour=0, minute=0, second=0
+        )
+
+        for step, delta, times in GRANULARITIES:
+            series = [start + (delta * i) for i in range(times)]
+            series_ts = [int(to_timestamp(ts)) for ts in series]
+
+            assert self.db.get_optimal_rollup(series[0], series[-1]) == step
+
+            assert self.db.get_optimal_rollup_series(series[0], end=series[-1], rollup=None) == (
+                step,
+                series_ts,
+            )
+
+            for time_step in series:
+                _, _, group_info = self.store_search_issue(
+                    project_id=project.id,
+                    user_id=0,
+                    fingerprints=[f"test_range_group_manual_group_time_rollup-{step}"],
+                    environment=None,
+                    insert_time=time_step,
+                )
+
+            assert self.db.get_range(
+                TSDBModel.group_generic,
+                [group_info.group.id],
+                series[0],
+                series[-1],
+                rollup=None,
+            ) == {group_info.group.id: [(ts, 1) for ts in series_ts]}
+
     def test_range_groups_mult(self):
         now = (datetime.utcnow() - timedelta(days=1)).replace(
             hour=10, minute=0, second=0, microsecond=0, tzinfo=pytz.UTC