Skip to content

Parameterise integration tests across the three backends - #27

Merged
chmodas merged 4 commits into
trunkfrom
backend-parameterisation
Apr 28, 2026
Merged

Parameterise integration tests across the three backends#27
chmodas merged 4 commits into
trunkfrom
backend-parameterisation

Conversation

@chmodas

@chmodas chmodas commented Apr 28, 2026

Copy link
Copy Markdown
Owner

No description provided.

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-commenter

codecov-commenter commented Apr 28, 2026

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.90%. Comparing base (15c65e2) to head (8717087).
⚠️ Report is 4 commits behind head on trunk.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

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.
📢 Have feedback on the report? Share it here.

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

chmodas added 2 commits April 28, 2026 09:08
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
chmodas force-pushed the backend-parameterisation branch from f9f9959 to 797a4dc Compare April 28, 2026 10:34
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.
@chmodas
chmodas merged commit 0c440e9 into trunk Apr 28, 2026
2 checks passed
@chmodas
chmodas deleted the backend-parameterisation branch April 28, 2026 11:11
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.

2 participants