Skip to content

Speed up database test setup#825

Merged
lewisjared merged 5 commits into
mainfrom
perf/test-db-template
Jul 15, 2026
Merged

Speed up database test setup#825
lewisjared merged 5 commits into
mainfrom
perf/test-db-template

Conversation

@lewisjared

@lewisjared lewisjared commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Description

Reuses a session scoped migrated SQLite template across isolated test databases. This avoids repeated Alembic migrations while keeping dedicated coverage for fresh database migrations.

Moves the full ESGF solver regression to the main slow suite. Pull request CI retains fast solver output-contract coverage against a representative catalog.

Runs test-ref-unit in four xdist workers on public GitHub hosted Linux runners. Coverage records each worker and subprocess, then combines their data before reporting.

Matched clean worktrees showed the template change reduced test-ref-unit from 293.53 to 164.27 seconds. The slow-regression split further reduced the current branch from 181.16 to 136.31 seconds locally. Four local workers completed the current no-slow unit suite in 59.06 seconds.

Checklist

Please confirm that this pull request has done the following:

  • Tests added
  • Documentation added (where applicable)
  • Changelog item added to changelog/

Summary by CodeRabbit

  • Bug Fixes
    • Improved CLI database handling to ensure a migrated database template is used for database access.
    • Strengthened test database initialisation so migrations aren’t repeatedly re-run unnecessarily.
  • Performance
    • Reduced unit test runtime by reusing migrated database templates and running checks in parallel.
    • Moved full solver regression coverage into the slower suite.
  • CI
    • Improved parallel test execution and coverage reporting by combining coverage results before generating reports.
    • Expanded coverage cleanup to remove all related coverage artefacts.
  • Documentation
    • Updated guidance for solver regression tests and baseline regeneration commands.
  • Tests
    • Refined fixtures and added/updated tests covering migrated database behaviour and solver test runtime classification.

Build the schema once and clone it for isolated test databases. This keeps explicit migration coverage while avoiding hundreds of repeated Alembic runs.

Confidence: high
@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: dfc2735e-341d-4b00-8f29-0b1cc6a4db44

📥 Commits

Reviewing files that changed from the base of the PR and between 8e04357 and 0b9c8c7.

📒 Files selected for processing (2)
  • packages/climate-ref/conftest.py
  • packages/climate-ref/tests/unit/datasets/test_datasets.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/climate-ref/conftest.py
  • packages/climate-ref/tests/unit/datasets/test_datasets.py

📝 Walkthrough

Walkthrough

Changes

Test infrastructure

Layer / File(s) Summary
Database template lifecycle
packages/climate-ref/conftest.py
Test databases are cloned from migrated or seeded SQLite templates, with centralised path resolution and migrations disabled for cloned instances.
CLI fixture execution
packages/climate-ref/src/climate_ref/conftest_plugin.py, packages/climate-ref/tests/unit/cli/test_db.py
CLI runner creation is separated from configuration, and migration-specific invocation is supported.
Fixture adoption and migration tests
packages/climate-ref/tests/unit/datasets/*, packages/climate-ref/tests/unit/cli/test_root.py, packages/climate-ref/tests/unit/test_testing.py
Dataset tests use injected databases, while CLI tests cover unmigrated database access and migrated-template usage.
Solver test inputs and selection
packages/climate-ref/tests/unit/test_solve_helpers.py, packages/climate-ref/tests/unit/test_solve_regression.py, docs/development.md, changelog/825.improvement.md
Example solve results are generated directly, regression tests are marked slow, and solver instructions and changelog text are updated.

Parallel coverage

Layer / File(s) Summary
Parallel coverage collection
pyproject.toml, Makefile
Coverage runs use parallel data files, omit append-based collection, combine outputs later, and clean generated fragments.
Coverage aggregation and CI parallelism
.github/workflows/ci.yaml, Makefile
Unit tests run with four pytest workers, and local and CI coverage reporting combines data before generating reports and XML.

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 78.26% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly captures the main change: speeding up database test setup.
Description check ✅ Passed The description includes the required sections and checklist items, and it is specific enough for the changeset.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch perf/test-db-template

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jul 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Flag Coverage Δ
core 92.50% <ø> (ø)
providers 86.86% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Keep the full ESGF regression on the main-only slow workflow. Run output contract tests against a representative catalog in pull request CI.

Confidence: high
Run the pull request unit suite in four module scoped workers. Collect and combine coverage from each worker before reporting.

Confidence: high

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
.github/workflows/ci.yaml (1)

65-65: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Run coverage reporting even if tests fail.

Currently, if any test step fails, the subsequent "Coverage report" step is skipped. This prevents the combination and upload of partial coverage data to Codecov, which can complicate debugging by missing coverage metrics on failing runs. Consider adding if: always() or if: success() || failure() to these steps to ensure coverage artifacts are always generated and uploaded.

  • .github/workflows/ci.yaml#L65-L65: Add if: always() to the "Coverage report" step in the tests-core job.
  • .github/workflows/ci.yaml#L103-L103: Add if: always() to the "Coverage report" step in the tests-integration job.
  • .github/workflows/ci.yaml#L148-L148: Add if: always() to the "Coverage report" step in the tests-providers job.
🛠️ Proposed fix for `.github/workflows/ci.yaml#L65-L65`
       - name: Coverage report
         # Per-job coverage is partial (the integration job covers the rest), so
         # the aggregate fail_under gate is enforced by codecov/project rather
         # than here -- both jobs upload to the same `core` flag.
+        if: always()
         run: |
           uv run coverage combine

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a75136d5-c2e1-41fa-b252-7721d406bf35

📥 Commits

Reviewing files that changed from the base of the PR and between 13af3cb and 8e04357.

📒 Files selected for processing (14)
  • .github/workflows/ci.yaml
  • Makefile
  • changelog/825.improvement.md
  • docs/development.md
  • packages/climate-ref/conftest.py
  • packages/climate-ref/src/climate_ref/conftest_plugin.py
  • packages/climate-ref/tests/unit/cli/test_db.py
  • packages/climate-ref/tests/unit/cli/test_root.py
  • packages/climate-ref/tests/unit/datasets/test_cmip_adapters.py
  • packages/climate-ref/tests/unit/datasets/test_datasets.py
  • packages/climate-ref/tests/unit/test_solve_helpers.py
  • packages/climate-ref/tests/unit/test_solve_regression.py
  • packages/climate-ref/tests/unit/test_testing.py
  • pyproject.toml

Comment thread packages/climate-ref/conftest.py
Comment thread packages/climate-ref/tests/unit/datasets/test_datasets.py
Cloning into a per-test config directory that already exists raised FileExistsError from mkdir(parents=True). Pass exist_ok=True so a pre-existing target directory is fine.

Also corrects the iter_local_datasets comment: CMIP6DatasetAdapter defines the method directly, and monkeypatch.delattr restores it after the test.
@lewisjared lewisjared merged commit e98f1fd into main Jul 15, 2026
28 checks passed
@lewisjared lewisjared deleted the perf/test-db-template branch July 15, 2026 08:38
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.

1 participant