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(data-modeling): freeze test clock at test start, not import (#73628)

Raúl Negrón-Otero75453bddf5db
diff --git a/posthog/temporal/tests/data_modeling/test_run_workflow.py b/posthog/temporal/tests/data_modeling/test_run_workflow.py
index 08f29db5791e..4555bbf58013 100644
--- a/posthog/temporal/tests/data_modeling/test_run_workflow.py
+++ b/posthog/temporal/tests/data_modeling/test_run_workflow.py
@@ -60,7 +60,13 @@ from products.warehouse_sources.backend.facade.models import DataWarehouseTable
pytestmark = [pytest.mark.asyncio, pytest.mark.django_db(transaction=True)]
-TEST_TIME = dt.datetime.now(dt.UTC)
+
+def test_time() -> dt.datetime:
+ # Freeze from test start rather than module import: boto3 signs S3 requests with the frozen
+ # clock, and the object store rejects a signature skewed by more than 15 minutes, so a shard
+ # that reaches this file late enough would fail every S3 call.
+ return dt.datetime.now(dt.UTC)
@pytest_asyncio.fixture
@@ -739,6 +745,7 @@ async def test_run_workflow_with_minio_bucket(
pageview_events,
saved_queries,
temporal_client,
+ test_time,
):
"""Test run workflow end-to-end using a local MinIO bucket."""
events, _ = pageview_events
@@ -764,7 +771,7 @@ async def test_run_workflow_with_minio_bucket(
DATAWAREHOUSE_LOCAL_BUCKET_REGION="us-east-1",
DATAWAREHOUSE_BUCKET_DOMAIN="objectstorage:19000",
),
- freeze_time(TEST_TIME),
+ freeze_time(test_time),
):
async with temporalio.worker.Worker(
temporal_client,
@@ -845,7 +852,7 @@ async def test_run_workflow_with_minio_bucket(
assert row == expected_data[index]
assert query.status == DataWarehouseSavedQuery.Status.COMPLETED
- assert query.last_run_at == TEST_TIME
+ assert query.last_run_at == test_time
assert query.is_materialized is True
# Verify row count was updated in the DataWarehouseTable
@@ -871,6 +878,7 @@ async def test_run_workflow_with_minio_bucket_with_errors(
pageview_events,
saved_queries,
temporal_client,
+ test_time,
):
workflow_id = str(uuid.uuid4())
inputs = RunWorkflowInputs(
@@ -889,7 +897,7 @@ async def test_run_workflow_with_minio_bucket_with_errors(
DATAWAREHOUSE_LOCAL_BUCKET_REGION="us-east-1",
DATAWAREHOUSE_BUCKET_DOMAIN="objectstorage:19000",
),
- freeze_time(TEST_TIME),
+ freeze_time(test_time),
unittest.mock.patch("posthog.temporal.data_modeling.run_workflow.materialize_model", mock_materialize_model),
):
async with temporalio.worker.Worker(
@@ -931,6 +939,7 @@ async def test_run_workflow_revert_materialization(
pageview_events,
saved_queries,
temporal_client,
+ test_time,
):
workflow_id = str(uuid.uuid4())
inputs = RunWorkflowInputs(team_id=ateam.pk)
@@ -946,7 +955,7 @@ async def test_run_workflow_revert_materialization(
DATAWAREHOUSE_LOCAL_BUCKET_REGION="us-east-1",
DATAWAREHOUSE_BUCKET_DOMAIN="objectstorage:19000",
),
- freeze_time(TEST_TIME),
+ freeze_time(test_time),
unittest.mock.patch("posthog.temporal.data_modeling.run_workflow.hogql_table", mock_hogql_table),
):
async with temporalio.worker.Worker(
@@ -992,6 +1001,7 @@ async def test_run_workflow_timeout_does_not_pause_schedule_without_consecutive_
pageview_events,
saved_queries,
temporal_client,
+ test_time,
):
"""Timeout should not pause the schedule when there aren't 5 consecutive timeout failures."""
for query in saved_queries:
@@ -1009,7 +1019,7 @@ async def test_run_workflow_timeout_does_not_pause_schedule_without_consecutive_
DATAWAREHOUSE_LOCAL_BUCKET_REGION="us-east-1",
DATAWAREHOUSE_BUCKET_DOMAIN="objectstorage:19000",
),
- freeze_time(TEST_TIME),
+ freeze_time(test_time),
unittest.mock.patch("posthog.temporal.data_modeling.run_workflow.hogql_table") as mock_hogql_table,
unittest.mock.patch(
"posthog.temporal.data_modeling.run_workflow.a_pause_saved_query_schedule"
@@ -1065,6 +1075,7 @@ async def test_run_workflow_timeout_pauses_schedule_after_5_consecutive_failures
pageview_events,
saved_queries,
temporal_client,
+ test_time,
):
"""Timeout should pause the schedule when there are 5 consecutive timeout failures."""
parent_query = saved_queries[0]
@@ -1090,7 +1101,7 @@ async def test_run_workflow_timeout_pauses_schedule_after_5_consecutive_failures
DATAWAREHOUSE_LOCAL_BUCKET_REGION="us-east-1",
DATAWAREHOUSE_BUCKET_DOMAIN="objectstorage:19000",
),
- freeze_time(TEST_TIME),
+ freeze_time(test_time),
unittest.mock.patch("posthog.temporal.data_modeling.run_workflow.hogql_table") as mock_hogql_table,
unittest.mock.patch(
"posthog.temporal.data_modeling.run_workflow.a_pause_saved_query_schedule"