: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(test): replace pointless sleeps in billing quota tests with flush (#66371)
Georges-Antoine Assib120ebd10aad
diff --git a/ee/billing/test/test_quota_limiting.py b/ee/billing/test/test_quota_limiting.pyindex cbcf52f2ea17..f9a3960eac5c 100644--- a/ee/billing/test/test_quota_limiting.py+++ b/ee/billing/test/test_quota_limiting.py@@ -1,9 +1,8 @@-import timefrom typing import Any, castfrom uuid import uuid4from freezegun import freeze_time-from posthog.test.base import BaseTest, FuzzyInt, _create_event+from posthog.test.base import BaseTest, FuzzyInt, _create_event, flush_persons_and_eventsfrom unittest.mock import patchfrom django.test import override_settings@@ -102,7 +101,7 @@ class TestQuotaLimiting(BaseTest):)org_id = str(self.organization.id)- time.sleep(1)+ flush_persons_and_events()quota_limited_orgs, quota_limiting_suspended_orgs, _stats = update_all_orgs_billing_quotas()# feature_enabled will be called for AI billing check and then for data retention flag@@ -225,7 +224,7 @@ class TestQuotaLimiting(BaseTest):self.organization.customer_trust_scores = zero_trust_scores()self.organization.save()- time.sleep(1)+ flush_persons_and_events()with self.assertNumQueries(FuzzyInt(3, 9)):quota_limited_orgs, quota_limiting_suspended_orgs, _stats = update_all_orgs_billing_quotas()assert patch_capture.call_count == 0 # No events should be captured since org won't be limited@@ -333,7 +332,7 @@ class TestQuotaLimiting(BaseTest):timestamp=now(),team=self.team,)- time.sleep(1)+ flush_persons_and_events()quota_limited_orgs, quota_limiting_suspended_orgs, _stats = update_all_orgs_billing_quotas()# Will be immediately rate limited as trust score was unset.org_id = str(self.organization.id)@@ -1827,7 +1826,7 @@ class TestQuotaLimiting(BaseTest):timestamp=now() - relativedelta(hours=1),team=self.team,)- time.sleep(1)+ flush_persons_and_events()fresh_usage = {"events": {"usage": 0, "limit": 10_000_000, "todays_usage": 0},@@ -1908,7 +1907,7 @@ class TestQuotaLimiting(BaseTest):timestamp=now() - relativedelta(hours=1),team=self.team,)- time.sleep(1)+ flush_persons_and_events()mid_loop_webhook = {"events": {"usage": 0, "limit": 50_000_000, "todays_usage": 0},@@ -1978,7 +1977,7 @@ class TestQuotaLimiting(BaseTest):timestamp=now() - relativedelta(hours=1),team=self.team,)- time.sleep(1)+ flush_persons_and_events()# A billing webhook lands a fresh paid plan with much higher limits before# the org loop reaches this org.@@ -2043,7 +2042,7 @@ class TestQuotaLimiting(BaseTest):timestamp=now() - relativedelta(hours=1),team=self.team,)- time.sleep(1)+ flush_persons_and_events()# Mid-loop downgrade lands a much lower limit; the 50 events from# ClickHouse now exceed it. A candidate-refresh would catch this; a