test(mongodb): run the integration suite via a shared testcontainer#209
Open
mauripunzueta wants to merge 2 commits into
Open
test(mongodb): run the integration suite via a shared testcontainer#209mauripunzueta wants to merge 2 commits into
mauripunzueta wants to merge 2 commits into
Conversation
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 Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This was referenced Jul 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The MongoDB integration suite (
crates/persistence/tests/mongodb_tests.rs) was gated onHFS_TEST_MONGODB_URLand 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
shared_mongoharness (OnceCell-backed) that prefersHFS_TEST_MONGODB_URLand 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.mongofeature ontestcontainers-modules.HFS_TEST_MONGODB_URL".Safety / blast radius
start()errors and the suite skips exactly as it does today.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_skippath. Everything else — CRUD, search, history, pagination, tenancy, conditional ops — now runs. Enabling transactions (viaMongo::repl_set()) is a reasonable follow-up.Test plan
Test Rust(cargo test --workspace --all-features) andCode Coverage(--features postgres,mongodb) now execute the Mongo suite against the container.