Skip to content

: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.

chore(tests): speed up person property reconciliation tests (#90198)

Paul D'Ambra878f09682043
diff --git a/posthog/dags/tests/conftest.py b/posthog/dags/tests/conftest.py
index 31278f60097a..107a70c1ecbe 100644
--- a/posthog/dags/tests/conftest.py
+++ b/posthog/dags/tests/conftest.py
@@ -4,6 +4,7 @@ from posthog.conftest import django_db_setup
__all__ = ["django_db_setup"]
from collections.abc import Iterator
+from contextlib import contextmanager
from datetime import datetime
from uuid import UUID
@@ -88,8 +89,8 @@ def _patched_get_cluster_hosts(self, client, cluster, retry_policy=None):
)
-def cluster(django_db_setup) -> Iterator[ClickhouseCluster]:
+@contextmanager
+def isolated_clickhouse_cluster() -> Iterator[ClickhouseCluster]:
"""
Cluster fixture with macOS Docker-compatible hostname resolution.
Patches ClickhouseCluster to use host_name instead of host_address.
@@ -107,3 +108,9 @@ def cluster(django_db_setup) -> Iterator[ClickhouseCluster]:
yield get_cluster()
finally:
reset_clickhouse_database_if_dirty()
+
+
+def cluster(django_db_setup) -> Iterator[ClickhouseCluster]:
+ with isolated_clickhouse_cluster() as clickhouse_cluster:
+ yield clickhouse_cluster
diff --git a/posthog/dags/tests/test_person_property_reconciliation.py b/posthog/dags/tests/test_person_property_reconciliation.py
index 66a2ab49999b..732c6074b5d8 100644
--- a/posthog/dags/tests/test_person_property_reconciliation.py
+++ b/posthog/dags/tests/test_person_property_reconciliation.py
@@ -38,11 +38,7 @@ from posthog.dags.person_property_reconciliation import (
reconcile_with_concurrent_changes,
update_person_with_version_check,
)
-from posthog.dags.tests.conftest import refresh_person_from_persons_db
-
-# Exercises the persons DB directly (raw reads and writes against the persons writer), so it must
-# run against the real persons DB rather than the personhog fake.
-pytestmark = pytest.mark.persons_db_direct
+from posthog.dags.tests.conftest import isolated_clickhouse_cluster, refresh_person_from_persons_db
class TestClickHouseResultParsing:
@@ -2757,6 +2753,11 @@ class TestPersonPropertyDiffsDataclass:
class TestClickHouseQueryIntegration:
"""Integration tests that insert data into ClickHouse and run the actual query."""
+ @pytest.fixture(scope="class")
+ def cluster(self, django_db_setup):
+ with isolated_clickhouse_cluster() as clickhouse_cluster:
+ yield clickhouse_cluster
+
def test_unset_uses_latest_timestamp_regression(self, cluster: ClickhouseCluster):
"""
Regression test: $unset should use max(timestamp), not min(timestamp).
@@ -4231,7 +4232,7 @@ class TestClickHouseQueryIntegration:
events after bug_window_start, regardless of when the person was originally created.
The bug window is about when the ingestion bug occurred, not when persons were created.
"""
- team_id = 99920
+ team_id = 99919
person_id = UUID("55550000-0000-0000-0000-000000000002")
now = datetime.now().replace(microsecond=0)
bug_window_start = now - timedelta(days=5)
@@ -5761,7 +5762,10 @@ class TestClickHouseQueryIntegration:
assert "email" in single_diff.unset_updates
+# Exercises the persons DB directly (raw reads and writes against the persons writer), so it must
+# run against the real persons DB rather than the personhog fake.
@pytest.mark.django_db(transaction=True)
class TestBatchCommitsEndToEnd:
"""End-to-end integration tests for batch commit functionality.
@@ -6118,6 +6122,7 @@ class TestBatchCommitsEndToEnd:
@pytest.mark.django_db(transaction=True)
class TestKafkaClickHouseRoundTrip:
"""Integration tests that verify person updates flow through Kafka to ClickHouse.