: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(ci): speed up async migration tests (#60348)
Raúl Negrón-Otero27e09966f243
diff --git a/.github/workflows/ci-backend.yml b/.github/workflows/ci-backend.ymlindex 0dbefb4d8cc4..fef074b20c91 100644--- a/.github/workflows/ci-backend.yml+++ b/.github/workflows/ci-backend.yml@@ -2248,9 +2248,29 @@ jobs:CLICKHOUSE_SERVER_IMAGE: ${{ matrix.clickhouse-server-image || needs.get_clickhouse_versions.outputs.oldest_supported_image }}run: bin/ci-wait-for-docker wait+ - name: Restore schema cache from master+ if: ${{ github.event_name == 'pull_request' && needs.turbo-discover.outputs.schema_cache_key != '' }}+ uses: actions/cache/restore@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3+ with:+ path: schema.sql.gz+ key: ${{ needs.turbo-discover.outputs.schema_cache_key }}++ - name: Prime test_posthog from cached schema+ # No-op on cache miss; pytest --reuse-db falls back to a full migrate.+ if: ${{ github.event_name == 'pull_request' }}+ run: |+ if [ ! -f schema.sql.gz ]; then+ echo "::notice::Schema cache miss — pytest --reuse-db will run full migrations"+ exit 0+ fi+ mkdir -p .postgres-backups+ mv schema.sql.gz .postgres-backups/schema-latest.sql.gz+ ./bin/hogli db:restore-test-db+- name: Run async migrations testsrun: |- pytest -m "async_migrations" --reruns 2 --reruns-delay 1 --junitxml=junit.xml+ # Scope async migration tests directly and reuse the primed test database.+ pytest posthog/async_migrations/test -m "async_migrations" --reuse-db --reruns 2 --reruns-delay 1 --durations=100 --durations-min=1.0 --junitxml=junit.xml- name: Upload test resultsuses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0diff --git a/posthog/async_migrations/test/test_definition.py b/posthog/async_migrations/test/test_definition.pyindex 6528ce3a34f9..84ea25e6af71 100644--- a/posthog/async_migrations/test/test_definition.py+++ b/posthog/async_migrations/test/test_definition.py@@ -1,6 +1,8 @@import pytestfrom posthog.test.base import BaseTest+from django.test import SimpleTestCase+from infi.clickhouse_orm.utils import import_submodulesfrom posthog.async_migrations.definition import AsyncMigrationDefinition, AsyncMigrationOperation@@ -15,7 +17,7 @@ from posthog.version_requirement import ServiceVersionRequirementpytestmark = pytest.mark.async_migrations-class TestAsyncMigrationDefinition(BaseTest):+class TestAsyncMigrationDefinition(SimpleTestCase):def test_get_async_migration_definition(self):from posthog.async_migrations.examples.example import example_fn, example_rollback_fn@@ -36,6 +38,8 @@ class TestAsyncMigrationDefinition(BaseTest):))++class TestAsyncMigrationDefinitionModel(BaseTest):def test_get_migration_instance_and_parameters(self):setup_async_migrations(ignore_posthog_version=True)diff --git a/posthog/async_migrations/test/test_utils.py b/posthog/async_migrations/test/test_utils.pyindex 2e80dd31b69b..daa4901c792f 100644--- a/posthog/async_migrations/test/test_utils.py+++ b/posthog/async_migrations/test/test_utils.py@@ -3,6 +3,8 @@ from datetime import UTC, datetime, timedeltaimport pytestfrom unittest.mock import patch+from django.test import SimpleTestCase+from posthog.async_migrations.definition import AsyncMigrationOperationSQLfrom posthog.async_migrations.test.util import AsyncMigrationBaseTest, create_async_migrationfrom posthog.async_migrations.utils import (@@ -23,7 +25,7 @@ DEFAULT_CH_OP = AsyncMigrationOperationSQL(sql="SELECT 1", rollback=None, timeouDEFAULT_POSTGRES_OP = AsyncMigrationOperationSQL(database=AnalyticsDBMS.POSTGRES, sql="SELECT 1", rollback=None)-class TestUtils(AsyncMigrationBaseTest):+class TestExecuteOp(SimpleTestCase):@patch("posthog.clickhouse.client.sync_execute")def test_execute_op_clickhouse(self, mock_sync_execute):execute_op(DEFAULT_CH_OP, "some_id")@@ -31,6 +33,8 @@ class TestUtils(AsyncMigrationBaseTest):# correctly routes to chmock_sync_execute.assert_called_once_with("SELECT 1", None, settings={"max_execution_time": 10})++class TestUtils(AsyncMigrationBaseTest):@patch("django.db.connection.cursor")def test_execute_op_postgres(self, mock_cursor):execute_op(DEFAULT_POSTGRES_OP, "some_id")