Parameterise integration tests across the three backends - #27
Merged
Conversation
Scaffolding for collapsing the ~95% structural duplication across tests/sqlite.rs, tests/postgres.rs, and tests/mysql.rs. - Add Dialect struct and SQLITE_DIALECT / POSTGRES_DIALECT / MYSQL_DIALECT constants supplying per-backend SQL fragments (column types, etc.) that parameterised bodies need. - Move test_annotations() and assert_annotated_span() from per-backend duplicates into tests/common.rs, parameterising the latter over &Dialect so the three backends share one definition. Add assert_one_annotated_span() for the recurring trailing assertion block. - Add fresh_table! macro: DROP IF EXISTS + CREATE TABLE so parameterised bodies behave identically against fresh sqlite :memory: pools and shared postgres / mysql containers. - Migrate execute_creates_span_via_pool to a test_execute_creates_span_via_pool! macro, proving the macro_rules approach works across all three backends.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## trunk #27 +/- ##
=======================================
Coverage 99.90% 99.90%
=======================================
Files 12 12
Lines 2030 2030
=======================================
Hits 2028 2028
Misses 2 2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Move 75 backend-portable tests into shared `macro_rules!` macros in tests/common.rs and replace each backend file's body with a one-line wrapper. Categories migrated: execute / execute_many / fetch / fetch_many / fetch_all / fetch_one / fetch_optional (portable subsets), prepare / prepare_with / describe, query_* / query_as_* / query_scalar_* / query_map_* / map_* with annotations, the metric / annotation / span auxiliary tests, and the builder / pool-close / QueryTextMode::Off tests (via a new per-backend `raw_pool()` helper).
Replace the recurring `let spans = tel.spans(); assert_eq!(spans.len(), 1); assert_annotated_span(&spans[0], &<DIALECT>);` block at the end of every sqlx::query!() / query_as!() / query_scalar!() macro test with a single `common::assert_one_annotated_span(&tel, &<DIALECT>)` call. Macro bodies themselves stay backend-specific (compile-time literal SQL). Also migrates `operation_duration_metric_is_recorded`, `pool_close_and_is_closed`, and the two `query_text_mode_*` tests in postgres.rs and mysql.rs to the shared macros (these were missed by an earlier pattern that required `let tel = …` as the first body line).
chmodas
force-pushed
the
backend-parameterisation
branch
from
April 28, 2026 10:34
f9f9959 to
797a4dc
Compare
testcontainers-rs 0.27 has no Ryuk reaper – it relies on `ContainerAsync::Drop`, which the language never runs for values held in a `'static` (the `OnceLock<OnceCell<SharedContainer>>` introduced in c29f995). The result was that postgres and mysql containers leaked after every test run. Capture the container ID into a sibling `static CONTAINER_ID: OnceLock<String>` at start-time and add a `#[ctor::dtor]`-registered function that shells out `docker rm -f <id>` synchronously when the test process exits. Restores the cleanup invariant of the per-test container pattern that existed before c29f995, without giving up the shared-container speedup.
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.
No description provided.