:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
chore(tests): shorten cohort deletion polling (#103800)
Paul D'Ambrab8711c18594a
diff --git a/posthog/models/test/test_async_deletion_model.py b/posthog/models/test/test_async_deletion_model.pyindex 2ab222a5a722..6019e75566d1 100644--- a/posthog/models/test/test_async_deletion_model.py+++ b/posthog/models/test/test_async_deletion_model.py@@ -9,6 +9,7 @@ from posthog.test.base import (snapshot_clickhouse_alter_queries,snapshot_clickhouse_queries,)+from unittest.mock import patchfrom posthog.clickhouse.client import sync_executefrom posthog.models import AsyncDeletion, DeletionType, Team, User@@ -446,7 +447,7 @@ class TestAsyncDeletion(ClickhouseTestMixin, ClickhouseDestroyTablesMixin, BaseTkey=str(cohort_id) + "_0",created_by=self.user,)- sweep_cohort_deletions()+ self._sweep_cohort_deletions()self.assertRowCount(0, "cohortpeople")@@ -462,7 +463,7 @@ class TestAsyncDeletion(ClickhouseTestMixin, ClickhouseDestroyTablesMixin, BaseTkey=str(cohort_id) + "_3",created_by=self.user,)- sweep_cohort_deletions()+ self._sweep_cohort_deletions()self.assertRowCount(1, "cohortpeople")@@ -475,7 +476,7 @@ class TestAsyncDeletion(ClickhouseTestMixin, ClickhouseDestroyTablesMixin, BaseTAsyncDeletion.objects.create(deletion_type=DeletionType.Cohort_stale, team_id=team.pk, key="11_2")AsyncDeletion.objects.create(deletion_type=DeletionType.Cohort_stale, team_id=team.pk, key="12_9")- sweep_cohort_deletions()+ self._sweep_cohort_deletions()# Cohort 11 asked for versions below 2 and nothing is below 2, so it is done.assert AsyncDeletion.objects.get(key="11_2").delete_verified_at is not None@@ -493,9 +494,13 @@ class TestAsyncDeletion(ClickhouseTestMixin, ClickhouseDestroyTablesMixin, BaseTdeletion_type=DeletionType.Cohort_full, team_id=team.pk, key=f"13_0_{self.teams[1].pk}")- assert sweep_cohort_deletions().failed == ()+ assert self._sweep_cohort_deletions().failed == ()self.assertRowCount(0, "cohortpeople")+ def _sweep_cohort_deletions(self):+ with patch("posthog.models.async_deletion.delete_cohorts.COHORT_MUTATION_POLL_SECONDS", 0.01):+ return sweep_cohort_deletions()+def assertRowCount(self, expected, table="events"):result = sync_execute(f"SELECT count() FROM {table}")[0][0]self.assertEqual(result, expected)