Skip to content

test(mongodb): run the integration suite via a shared testcontainer#209

Open
mauripunzueta wants to merge 2 commits into
mainfrom
test/mongo-suite-testcontainers
Open

test(mongodb): run the integration suite via a shared testcontainer#209
mauripunzueta wants to merge 2 commits into
mainfrom
test/mongo-suite-testcontainers

Conversation

@mauripunzueta

Copy link
Copy Markdown
Contributor

Summary

The MongoDB integration suite (crates/persistence/tests/mongodb_tests.rs) was gated on HFS_TEST_MONGODB_URL and skipped entirely in CI — the whole MongoDB backend went unexercised there unless a developer pointed the tests at an external server. This mirrors how the PostgreSQL suite already provisions itself with testcontainers.

This PR makes the suite provision MongoDB automatically: a single ephemeral standalone Mongo testcontainer, shared across the test binary, started on demand when no URL is set. Docker is available in the CI test/coverage jobs, so the suite now runs for everyone — and every future MongoDB test inherits this with zero extra setup.

Changes

  • Add a shared_mongo harness (OnceCell-backed) that prefers HFS_TEST_MONGODB_URL and otherwise starts one standalone Mongo container for the whole binary. All four backend-creation sites now source their connection string from it; each test keeps its own unique database name.
  • Enable the test-only mongo feature on testcontainers-modules.
  • Refresh the file header + skip messages to reflect "Docker or HFS_TEST_MONGODB_URL".

Safety / blast radius

  • Test-only change — no production code touched.
  • Cannot break CI, only add coverage: if Docker is unavailable (or the container can't become ready), start() errors and the suite skips exactly as it does today.
  • The same standalone-container harness already shipped and passed CI in feat: per-user JSON UI settings store #151 (it ran the settings-store tests and lifted their coverage), so the runner is known to support it.

Known limitation (intentional, documented)

Multi-document transactions require a replica set; a standalone server doesn't provide one, so the transaction tests continue to skip only their transaction-specific assertions via the existing process_transaction_or_skip path. Everything else — CRUD, search, history, pagination, tenancy, conditional ops — now runs. Enabling transactions (via Mongo::repl_set()) is a reasonable follow-up.

Test plan

  • CI Test Rust (cargo test --workspace --all-features) and Code Coverage (--features postgres,mongodb) now execute the Mongo suite against the container.

The MongoDB integration suite was gated on HFS_TEST_MONGODB_URL and skipped
entirely in CI, so the whole mongodb backend went unexercised there unless a
developer pointed the tests at an external server. Provision MongoDB
automatically instead: a single ephemeral standalone Mongo testcontainer,
shared across the test binary, started on demand when no URL is set. Docker
is available in the CI test/coverage jobs, so the suite now runs for
everyone — and every future MongoDB test inherits this with no extra setup.

- Add a `shared_mongo` harness that prefers HFS_TEST_MONGODB_URL and
  otherwise starts (once) a standalone Mongo container; all backend-creation
  sites now source their connection string from it.
- Enable the test-only `mongo` feature on testcontainers-modules.
- If neither a URL nor Docker is available the tests skip, so no environment
  is hard-broken. Multi-document transaction tests still skip their
  transaction-specific assertions on a standalone server (they need a replica
  set) via the existing graceful-skip path.
Four tests search by `identifier` (a token) but were built with the
embedded search-parameter registry, which doesn't load `identifier` — so
the search index had no entries, token search returned nothing, and the
conditional-create/update tests fell through to Created/NoMatch. They never
ran in CI (the suite skipped), so the mis-configuration went unnoticed.

Point them at create_backend_with_full_registry (as the other search tests
already do), which loads the FHIR SearchParameter specs so `identifier` is
indexed and searchable.

Fixes the 4 failures surfaced once the suite began running against the
testcontainer:
- mongodb_integration_conditional_create_exists
- mongodb_integration_conditional_update_delete_and_no_match
- mongodb_integration_conditional_create_multiple_matches
- mongodb_integration_search_token_string_and_offset_pagination
@codecov

codecov Bot commented Jul 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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