Skip to content

group integration tests into grp_* harnesses - #1755

Merged
zonotope merged 3 commits into
chore/dev-profile-split-debuginfofrom
refactor/consolidate-test-harness
Sep 1, 2026
Merged

zonotope merged 3 commits into
chore/dev-profile-split-debuginfofrom
refactor/consolidate-test-harness

Conversation

@zonotope

@zonotope zonotope commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

fluree-db-server had 28 auto-discovered integration test targets — one per tests/*.rs file. Every one of them is a bin that links the entire workspace dependency graph, so the crate paid 28 full link steps on every test build. This groups them by domain into 7 harnesses plus 2 deliberately standalone binaries, taking the crate from 28 test binaries to 9, using the same pattern fluree-db-api already established: autotests = false, explicit [[test]] declarations, and each case file pulled in as a module via #[path].

No test code moves and no test file is edited. All 338 integration tests are preserved exactly, verified by name rather than by count.

What changed

  • 7 domain harnesses added — grp_http, grp_query, grp_proxy, grp_policy, grp_search, grp_raft, grp_bolt. Each is a short list of #[path = "…"] mod …; lines, matching the existing style in fluree-db-api/tests/grp_*.rs.
  • fluree-db-server/Cargo.toml — autotests = false in [package], plus 9 [[test]] declarations and comments explaining why auto-discovery is off and why two suites stay standalone.
  • tests/harness_coverage.rs — a new guard test (see below).
  • docs/contributing/tests.md — the grouped-binary section now documents fluree-db-server alongside fluree-db-api.

How this improves the codebase

Fewer link steps. 19 fewer full links of the workspace dependency tree per test build of this crate. Linking is the dominant cost of building this test suite, and it is work that no incremental-compilation or compiler-cache scheme can avoid — sccache, for instance, explicitly cannot cache crates that invoke the system linker.

Less disk per build. Measured on this branch, each linked server test binary is 436–463 MB (with split-debuginfo = "unpacked" from the base branch already applied). Removing 19 of them cuts roughly 8 GB of linked output from a full --all-features test build. That figure is derived from the measured per-binary size rather than a direct before/after of the whole tree, but every removed binary was a full link, so it is a sound multiplication rather than a guess.

The disk saving multiplies across working copies. Each git worktree, CI cache entry, and developer checkout carries its own target/. Three worktrees previously carried three independent copies of those 19 redundant binaries.

Closes a silent-failure hole that autotests = false opens. This is the one real hazard the pattern introduces: with auto-discovery off, a new tests/*.rs that nobody wires into a harness is never compiled and never run — and cargo test still reports success. tests/harness_coverage.rs asserts that every tests/*.rs is either pulled into a harness or declared as its own [[test]] target, failing with the list of orphans. This is not hypothetical: an untracked tests/ledger_route_config_defaults.rs exists on another branch and would have silently stopped running once this merged. The guard was verified against a synthetic orphan file — it fails naming the file, and passes once the file is wired up.

Brings the crate in line with a documented convention that previously covered only one crate. docs/contributing/tests.md described the grouping pattern and its standalone rules for fluree-db-api alone. It now covers fluree-db-server too, so a contributor adding a server integration test finds the rule instead of discovering autotests = false by surprise from a Cargo.toml comment.

Preserves history. The 28 test files are neither moved nor edited, so git blame is intact across all 22k lines of test code. The entire diff is 193 added lines.

Grouping reflects what the code actually does. Harnesses are organised by domain, not by feature flag. raft is the only non-default feature in this crate (default = ["native", "credential", "iceberg", "shacl", "bolt"]), so grp_raft is the only harness that compiles to an empty binary on a default build.

Two suites intentionally left standalone

telemetry_test and multi_query_tracing_integration keep their own binaries. Both install a tracing subscriber and assert on the events captured through it. Tracing's callsite-interest cache is process-global while the capture is thread-local, so those assertions are only reliable when the test is alone in its process under bare cargo test. This is exactly the rule docs/contributing/tests.md already states for fluree-db-api, now applied consistently here.

They do pass inside a shared harness today, because their captures happen to sit on current_thread runtimes — but that is a coincidence of the current test bodies, not a property the tests guarantee, so they are kept isolated by rule rather than by luck.

Safety of sharing a process

Grouping means tests that previously had a process each now share one under bare cargo test. (Under cargo nextest, which CI uses, every test still gets its own process, so CI semantics are unchanged.) All 28 files were audited for process-global hazards:

  • No set_var / remove_var anywhere.
  • No OnceLock / OnceCell / LazyLock / lazy statics latching process state.
  • No set_current_dir, no RLIMIT manipulation, no self re-exec.
  • No tests that are process-fatal by construction (e.g. deliberate stack-overflow probes).
  • The only global subscriber install is raft_multi_node, which is Once-guarded with try_init() and therefore idempotent.
  • The only two suites asserting on captured instrumentation are kept standalone, as above.

Filesystem isolation was already sound — the suites use tempfile/TempDir throughout — and every real listener binds an ephemeral 127.0.0.1:0 port, so there are no fixed-port collisions between concurrently running tests.

Notes for reviewers and after merge

  • Adding [[test]] targets and turning off auto-discovery changes which artifacts Cargo produces. The 28 old per-file test binaries linger in existing target/ directories as unreferenced garbage until a cargo clean. Harmless, but worth running once if you care about the disk reclaim this PR is about.
  • fluree-db-api has the same autotests = false silent-drop exposure and no coverage guard. That is pre-existing and out of scope here, but tests/harness_coverage.rs is written to be portable — dropping a copy into that crate would protect its ~160 test files too.

fluree-db-server had 28 auto-discovered integration test targets, one per
tests/*.rs file. Each is a `bin` that links the full workspace dependency tree,
so the crate paid 28 separate link steps on every test build. This takes it to
9.

Group them using the pattern fluree-db-api already establishes: `autotests =
false` plus explicit [[test]] declarations, with each harness pulling its
members in via #[path]/mod. The 28 test files are not moved or edited, so git
blame is preserved across all 22k lines. Grouping is by domain (grp_http,
grp_query, grp_proxy, grp_policy, grp_search, grp_raft, grp_bolt), not by
feature. `raft` is the only non-default feature here (default = native,
credential, iceberg, shacl, bolt), so grp_raft is the only harness that compiles
to an empty binary on a default build.

telemetry_test and multi_query_tracing_integration keep their own binaries. Both
install a tracing subscriber and assert on the events captured through it, and
tracing's callsite-interest cache is process-global while the capture is
thread-local, so those assertions are only reliable when the test is alone in
its process under bare `cargo test`. docs/contributing/tests.md already states
that rule for fluree-db-api; it now covers this crate too.

`autotests = false` also means a new tests/*.rs that nobody wires into a harness
never compiles and never runs, with `cargo test` still reporting success.
tests/harness_coverage.rs asserts every tests/*.rs is either pulled into a
harness or declared as its own [[test]], and names the orphans when it fails.

Verified under bare `cargo test`, not just nextest. nextest gives every test its
own process and cannot detect the shared-process hazards this layout introduces.
@zonotope
zonotope requested review from aaj3f and bplatz September 1, 2026 10:15

@bplatz bplatz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One gap worth closing before merge: harness_coverage skips anything named grp_*, and it harvests #[path] lines from the filesystem — so a grp_*.rs that nobody declares as a [[test]] escapes the guard entirely, and the files it references count as covered while nothing compiles or runs them (verified locally with a demo harness). Small fix: also assert every tests/grp_*.rs appears as a [[test]] path in Cargo.toml.

Suggested follow-up (separate PR/issue): port the guard to fluree-db-api — it has the same layout and far more test files, and the docs added here already tell adopters to add one.

The guard skipped anything named grp_*, assuming it must be declared as a
[[test]] target, and harvested #[path] lines from every file on disk. An
undeclared tests/grp_foo.rs therefore escaped the check while its members
counted as covered. A whole harness could go missing with the guard still
reporting success.

Derive reachability from Cargo.toml instead: parse the [[test]] blocks, harvest
The filename special case is removed rather than supplemented. The parser also
handles targets that omit `path`, which fluree-db-api uses and a port will need.
@zonotope

zonotope commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

One gap worth closing before merge: harness_coverage skips anything named grp_*, and it harvests #[path] lines from the filesystem — so a grp_*.rs that nobody declares as a [[test]] escapes the guard entirely, and the files it references count as covered while nothing compiles or runs them (verified locally with a demo harness). Small fix: also assert every tests/grp_*.rs appears as a [[test]] path in Cargo.toml.

This was addressed in fb576f6

Suggested follow-up (separate PR/issue): port the guard to fluree-db-api — it has the same layout and far more test files, and the docs added here already tell adopters to add one.

Good idea. I'll do this in another branch

@zonotope
zonotope merged commit 51b69ee into chore/dev-profile-split-debuginfo Sep 1, 2026
8 checks passed
@zonotope
zonotope deleted the refactor/consolidate-test-harness branch September 1, 2026 20:10
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