Skip to content

perf(testing): share MongoDB across vibetuner_db tests#1726

Merged
davidpoblador merged 1 commit into
mainfrom
fix/vibetuner-db-fixture-perf
Apr 28, 2026
Merged

perf(testing): share MongoDB across vibetuner_db tests#1726
davidpoblador merged 1 commit into
mainfrom
fix/vibetuner-db-fixture-perf

Conversation

@davidpoblador

Copy link
Copy Markdown
Member

Summary

Closes #1721.

  • vibetuner_db now sits on top of a session-scoped MongoDB database. Beanie index registration runs once for the whole test session instead of once per test.
  • Per-test setup/teardown truncates every non-system collection. Truncating before and after each test makes the fixture self-healing if a test crashed mid-run.
  • Per-test init_beanie runs with skip_indexes=True since the indexes already live on the shared DB. Uniqueness/index behavior is preserved.
  • Session DB name includes PYTEST_XDIST_WORKER so parallel runs don't collide.

Validation

  • Radio's full suite: 178s → 151s (15% faster), all 107 tests passing. The remaining per-test cost is the fresh AsyncMongoClient handshake (TCP+TLS+auth ~5-8 RTTs) — pymongo binds the client to its event loop, so reusing the session client would force every test using vibetuner_db onto a session-scoped event loop, which is a breaking change for downstream test suites.
  • New integration tests under vibetuner-py/tests/integration/ use testcontainers[mongodb] for a real Dockerised Mongo. They cover: cross-test data isolation, session DB reuse, and persistence of unique-index enforcement across per-test cleanup.

Caveats / breaking-change risks

Documented in the fixture docstring and the docs site:

  • All tests share one DB. Tests can't assert on database-level state (existence, name, full collection drops).
  • Indexes persist across tests. Tests that drop/recreate indexes will see cross-test contamination.
  • Concurrent runs need pytest-xdist; otherwise multiple processes pointing at the same Mongo will collide on the session DB.

Test plan

  • uv run python -m pytest tests/unit/test_vibetuner_db_fixture.py
  • DOCKER_HOST=… uv run python -m pytest tests/integration/test_vibetuner_db_real.py
  • cd /Users/dpoblador/repos/radio && uv run python -m pytest tests/ against patched vibetuner-py

🤖 Generated with Claude Code

Move the per-test database to a session-scoped fixture so init_beanie
runs index registration once per test session instead of per test.
Each test still gets a clean slate via per-collection truncation
(setup + teardown), and per-test init_beanie now runs with
skip_indexes=True since indexes already exist on the shared DB.

Index/uniqueness behavior is preserved because indexes live on the
session DB. Per-xdist-worker DB namespacing keeps parallel runs
isolated.

Validated against radio's full suite: 178s -> 151s (15% faster), all
107 tests passing. Local Mongo via testcontainers covers the new
integration tests for cross-test isolation, cleanup, and uniqueness.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@davidpoblador davidpoblador merged commit c9064e4 into main Apr 28, 2026
2 checks passed
@davidpoblador davidpoblador deleted the fix/vibetuner-db-fixture-perf branch April 28, 2026 10:17
davidpoblador pushed a commit that referenced this pull request Apr 28, 2026
🤖 I have created a release *beep* *boop*
---


##
[10.8.0](v10.7.0...v10.8.0)
(2026-04-28)


### Features

* add BrandSettings env-var surface for favicon and email branding
([#1720](#1720))
([3d22717](3d22717))
* i18n primitives for per-tenant locale flows
([#1718](#1718))
([177fe5e](177fe5e))


### Bug Fixes

* restore gettext plural-form support in lint-po
([#1725](#1725))
([fe0dacb](fe0dacb))
* **template:** scope babel.cfg python extraction to src/
([#1722](#1722))
([b729964](b729964))
* theme default screens with DaisyUI semantic tokens
([#1714](#1714))
([4467168](4467168))


### Performance Improvements

* **testing:** share MongoDB across vibetuner_db tests
([#1726](#1726))
([c9064e4](c9064e4))


### Miscellaneous Chores

* **py:** use PEP 639 SPDX license expression
([#1727](#1727))
([855f9f4](855f9f4))


### Documentation Updates

* **i18n:** clarify locale_names vs language_picker overlap
([#1723](#1723))
([87733bd](87733bd))
* **template:** document i18n primitives in scaffolded agent rules
([#1724](#1724))
([27a3b98](27a3b98))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.

Test infra: vibetuner_db fixture is per-test scoped, ~4s/test on remote MongoDB

1 participant