Skip to content

perf(sqlalchemy-bigquery): parallelize compliance tests with worker-partitioned datasets and pytest-xdist - #18534

Merged
chalmerlowe merged 11 commits into
mainfrom
perf/sqlalchemy-bigquery-compliance-xdist
Oct 1, 2026
Merged

chalmerlowe merged 11 commits into
mainfrom
perf/sqlalchemy-bigquery-compliance-xdist

Conversation

@chalmerlowe

Copy link
Copy Markdown
Contributor

Summary

Parallelizes the sqlalchemy-bigquery dialect compliance suite using pytest-xdist to reduce execution time from ~140 minutes down to ~35-45 minutes.

Key Changes

  1. Worker-Partitioned Datasets (sqlalchemy_bigquery.provision):
    • Implements SQLAlchemy's testing provisioning hooks (create_db, drop_db, follower_url_from_main) for BigQuery so each xdist worker runs in an isolated BigQuery dataset with a 1-hour expiration safety net.
    • Eliminates concurrent table collisions and distributes DDL quota consumption across separate datasets.
  2. Session Lifecycle (conftest.py):
    • Distinguishes xdist worker processes from the main runner to avoid duplicate master dataset creation and premature teardown.
  3. Parallel Execution (noxfile.py):
    • Configures the compliance session to install pytest-xdist and run tests with -n=4 and --dist=loadscope (keeping test classes together on the same worker).
    • Tunes rerun backoff settings (--reruns=2 --reruns-delay=30).

@chalmerlowe
chalmerlowe marked this pull request as ready for review September 30, 2026 23:49
@chalmerlowe
chalmerlowe requested review from a team as code owners September 30, 2026 23:49
@chalmerlowe
chalmerlowe requested review from Edvc97 and removed request for a team September 30, 2026 23:49

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request re-enables the sqlalchemy-bigquery package in CI, configures Nox to use the virtualenv backend to bypass an upstream packaging issue, and introduces parallel execution for compliance tests using pytest-xdist with dynamic dataset provisioning. Feedback on these changes highlights three key improvements: first, moving the initialization of COMPLIANCE_RUN_PREFIX to pytest_configure to ensure pytest-xdist worker processes correctly inherit the environment variable; second, persisting the generated prefix in os.environ within _dataset_id_from_ident to prevent inconsistent dataset IDs across calls; and third, checking for both -n and --numprocesses in noxfile.py to avoid duplicate arguments.

Comment thread packages/sqlalchemy-bigquery/tests/sqlalchemy_dialect_compliance/conftest.py Outdated
Comment thread packages/sqlalchemy-bigquery/sqlalchemy_bigquery/provision.py
Comment thread packages/sqlalchemy-bigquery/noxfile.py Outdated
…ist processes

Initialize COMPLIANCE_RUN_PREFIX in pytest_configure before workers are
spawned and propagate it via workerinput and environment variables. Also
cache fallback prefix in provision.py and recognize --numprocesses in
noxfile.
… dburi in xdist sessionstart

Implement generate_driver_url provision hook for bigquery dialect so
generate_db_urls resolves properly. Set dburi on workers and ensure worker
datasets exist during worker sessionstart to prevent NoSectionError.
@chalmerlowe
chalmerlowe force-pushed the perf/sqlalchemy-bigquery-compliance-xdist branch from f1f1da9 to f0c1f3b Compare October 1, 2026 11:05
"protobuf": ("https://googleapis.dev/python/protobuf/latest/", None),
}

# Check reachability of the Python standard library inventory before attaching it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: This check is in direct response to an issue that came up today: docs.python.org was not available on line for a period of time and was failing tests.


visit_REAL = visit_FLOAT
visit_REAL = visit_DOUBLE = visit_DOUBLE_PRECISION = visit_FLOAT

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is due to an upstream issue in sqlalchemy and how they handle DOUBLE and DOUBLE_PRECISION, which BigQuery does not recognize.

import google.cloud.bigquery
from sqlalchemy.engine import make_url
from sqlalchemy.testing.provision import (
create_db,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sqlalchemy provides decorators to help manage portions of db and url creation.
Most of the functions below are wrapped by the sqlalchemy decorators to align with their expectations and structured internally to handle nuances that are particular to our needs OR the BigQuery API.

@chalmerlowe
chalmerlowe merged commit 855bbde into main Oct 1, 2026
117 checks passed
@chalmerlowe
chalmerlowe deleted the perf/sqlalchemy-bigquery-compliance-xdist branch October 1, 2026 21:38
@release-please release-please Bot mentioned this pull request Oct 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants