: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(warehouse-sources): replace wall-clock glob test with a work bound (#121795)
Jimmy Zhu1e757f3f3813
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/common/object_store/tests/test_globs.py b/products/warehouse_sources/backend/temporal/data_imports/sources/common/object_store/tests/test_globs.pyindex df1443bfa7c3..6a16d1959e26 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/common/object_store/tests/test_globs.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/common/object_store/tests/test_globs.py@@ -1,6 +1,7 @@-import time+from typing import TYPE_CHECKINGimport pytest+from unittest.mock import patchfrom parameterized import parameterized@@ -8,11 +9,15 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.objObjectStorageError,)from products.warehouse_sources.backend.temporal.data_imports.sources.common.object_store.globs import (+ ClickHouseGlob,compile_clickhouse_glob,glob_key_prefix,glob_listing_prefix,)+if TYPE_CHECKING:+ from products.warehouse_sources.backend.temporal.data_imports.sources.common.object_store.globs import _State+class TestClickHouseGlob:@parameterized.expand(@@ -111,15 +116,25 @@ class TestClickHouseGlob:("eight_stars", "*a*a*a*a*a*a*a*a*b.csv"),])- def test_adversarial_match_time(self, _name: str, pattern: str) -> None:+ def test_adversarial_match_work_is_bounded(self, _name: str, pattern: str) -> None:glob = compile_clickhouse_glob(pattern)- path = "a" * 200 + ".csv"+ # Short enough that a backtracking matcher returns and fails the assertions below instead of hanging.+ path = "a" * 20 + ".csv"+ closure = ClickHouseGlob._epsilon_closure+ state_counts: list[int] = []++ def counting_closure(self: ClickHouseGlob, states: set[_State]) -> set[_State]:+ result = closure(self, states)+ state_counts.append(len(result))+ return result- started = time.perf_counter()- for _ in range(1000):+ with patch.object(ClickHouseGlob, "_epsilon_closure", counting_closure):assert glob.matches(path) is False- assert time.perf_counter() - started < 2- assert glob.matches("a" * 200 + "b.csv") is True++ # One state set per character, each no larger than the token count, keeps the work linear.+ assert 0 < len(state_counts) <= len(path) + 1+ assert max(state_counts) <= len(glob.tokens) + 1+ assert glob.matches("a" * 20 + "b.csv") is Truedef test_a_run_of_stars_is_one_wildcard(self) -> None:glob = compile_clickhouse_glob("*" * 1000 + ".csv")