Skip to content

refactor(tests): share the adapter test suite behind a common harness - #827

Open
LiamCarPer wants to merge 1 commit into
Totodore:mainfrom
LiamCarPer:refactor/share-adapter-test-suite
Open

LiamCarPer wants to merge 1 commit into
Totodore:mainfrom
LiamCarPer:refactor/share-adapter-test-suite

Conversation

@LiamCarPer

Copy link
Copy Markdown
Contributor

Closes #825, part of #727.

Motivation

The redis, postgres and mongodb adapter test suites were almost the same code copied three times: broadcast.rs was 96-97% identical, rooms.rs 99%, sockets.rs 86% and local.rs 100%. A change or a fix had to be made three times, and the redis regression test from #782 is a good example of a test that only landed in one adapter.

Solution

Added crates/adapter-test-suite (publish = false, dev-dependency of the three adapters):

  • Fixture trait implemented by each adapter: spawn_servers, spawn_buggy_servers and add_ns (the last one awaits the adapter init future, whose type/error differ per adapter).
  • The shared test bodies for broadcast, rooms, sockets and local, generic over F: Fixture.
  • The timeout_rcv!, timeout_rcv_err! and assert_now! macros.

Each adapter keeps its fixture.rs (the stub driver) plus a small Fixture impl, and its test files are now thin wrappers like:

#[tokio::test]
async fn broadcast() {
    adapter_test_suite::broadcast::broadcast::<fixture::Fixture>().await;
}

Adapter specific tests stay where they are: postgres attachments.rs, postgres/mongodb close.rs, and the redis remote_socket_emit_with_ack_targeted_terminates test from #782.

This also drops a couple of debug leftovers that had been copied into the postgres/mongodb tests (dbg! in rooms, a tracing_subscriber init in broadcast) since the shared bodies use the redis versions.

Tests

Same test count per adapter before and after (redis 29, postgres 29, mongodb 21). cargo test --all-features --workspace, cargo clippy --all-features --workspace --examples --tests -- -D warnings and cargo fmt --check are green.

Net: ~670 lines removed.

The broadcast, rooms, sockets and local test files were almost identical
in the three adapters. Move the test bodies into a new adapter-test-suite
crate with a Fixture trait, implemented by each adapter to spawn its
servers, and keep the adapter specific tests where they are (postgres
attachments, postgres/mongodb close, the redis targeted ack test).

Each adapter test file is now a thin wrapper that runs the shared test
with its fixture.

Closes Totodore#825
@codspeed

codspeed Bot commented Nov 9, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

1 warning

⚠️ 4 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 87 untouched benchmarks


Comparing LiamCarPer:refactor/share-adapter-test-suite (3ab1692) with main (d03ed5c)

Open in CodSpeed

This branch has not been deployed

No deployments
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.

Share the adapter test suite behind a common test harness

1 participant