Repository navigation
test: tracing captures and WAL flush counts that hold up under load - #2149
Conversation
A test that asserts on tracing output installs its subscriber as its own thread's default. Each callsite's interest is cached process-wide, and tracing-core computes a new callsite's interest from the registering thread's default alone while at most one dispatcher is registered, which a test capture often is. So a sibling test whose thread had no subscriber could hit a callsite first and cache it as never interesting, and the capture missed it: captures came back empty intermittently, failing presence assertions and passing absence ones vacuously. fluree_test_support::scoped_default and with_scoped_default first register, once per process, two dispatchers that are never a default and answer every callsite with sometimes. With two alive the one-dispatcher path is never taken and no combined interest is never, so each event reaches the capture's own enabled check. span_capture's init functions, the in-crate unit tests and the server's capture tests install through them, and three tests drop the cache rebuilds they had added as a partial workaround. harness_coverage gains scoped_subscribers_use_the_floor, which fails on a direct set_default or with_default anywhere in the workspace's src and tests. A test in fluree-test-support pins the mechanism: a callsite first hit on another thread reaches the capture.
The rule that tests asserting on instrumentation keep their own binary existed because a thread-local capture was unreliable next to parallel siblings. Captures installed through fluree_test_support::scoped_default are reliable there, so the rule now says to install through it, which harness_coverage checks. The standalone tests' headers say why they have a binary of their own and that they no longer need one; the one hazard a thread-local capture keeps, events emitted on other threads, stays noted.
Clippy refuses items after a test module.
fsyncs_issued counts every flush of the root's log, the background thread's included: it flushes an append left waiting, and closes a segment a second old and retires it, flushing every file the segment covered. A test that counts one commit's flushes therefore counted the thread's too whenever the commit ran late enough to meet one, which a loaded machine makes likely (a_transaction_costs_one_flush saw 15 for 1). The tests that count a window of flushes on a live log now pause the thread for it, with a test hook that waits out a pass already under way. Two are in fluree-db-core's own suite, two in it_wal.
pause_wal_background_for_test, and the state behind it, compile only in fluree-db-core's own tests and under a new test-hooks feature, which fluree-db-api enables from its dev-dependencies. A production build has the background thread exactly as before.
|
Folded in one more of the same class: |
bplatz
left a comment
There was a problem hiding this comment.
Approving. The interest-floor reasoning matches how tracing-core works, the WAL pause covers the background thread's only entry point, and test-hooks stays out of production builds under resolver 2.
One nit inline. Also, the branch is 64 commits behind main. It merges cleanly and main has no new direct installs, so the guard stays green, but an update from main would get CI on the current base. @aaj3f please go through the feedback before merging.
| "subscriber::set_default(", | ||
| "subscriber::with_default(", | ||
| "dispatcher::set_default(", | ||
| "dispatcher::with_default(", |
There was a problem hiding this comment.
Nit: the method form from tracing-subscriber (fmt().with_test_writer().set_default(), via SubscriberInitExt) slips past this. Nothing uses it today, but it's the likeliest way a new test bypasses the floor. Add .set_default() here, or list it in the doc's blind spots.
There was a problem hiding this comment.
Good call, that's the likeliest way in. The scan now looks for .set_default() too (61eb42f8d), and the doc names the method form. the_floor_guard_names_each_direct_install builds a throwaway workspace with a function-form install in src/, a fmt().with_test_writer().set_default() in src/, a dispatcher::with_default in tests/ and a commented-out call. It checks that all three are named by file:line and the comment isn't. the_floor_guard_passes_installs_through_the_helper checks that a scoped_default install passes. Take .set_default() back out of the list and the first fails on m/src/lib.rs:2. Nothing in the workspace uses the method form today, so the guard stays green.
…iable # Conflicts: # fluree-db-api/tests/support/span_capture.rs
Main added a thread-local capture of the collector's info events, installed with subscriber::set_default; it now goes through scoped_default like every other capture, so the floor guard stays green.
fmt().with_test_writer().set_default(), through SubscriberInitExt, installs a thread-local default as subscriber::set_default does, and the guard did not look for it. It does now, and two tests pin what it names: every direct form, in src/ and tests/, by file:line, and not a commented-out call.
|
Thanks for going through this so carefully. I merged main ( Your Main had also picked up one new direct install since your review: |
Brings #2217 (SPARQL reads list members as values; CONSTRUCT writes lists), #2218 (schema writes judged by modify policy), #2208, #2169, #2168, #2153, #2149 and #2148 into next. Resolutions: - Nameservice: branch_records is the one branch listing (strict, retracted branches kept for GC) on every backend, resolved through next's bindings; Fluree::list_branches filters retracted ones. The lifecycle conformance suite reads live branches through a helper. DynamoDB's narrow listing is wired into its trait impl. - JSON-LD adapter: main's graph scoping (Walk, Scope, node_graph, selectors) with next's triple terms, @annotation, @reifies, blank-label and number datatype handling. to_graph_events writes a JSON-LD named graph under its @id and refuses a graph selector. main's f:reifiesGraph anchor is dropped: next writes an annotation as an rdf:reifies link in its graph. emit_quad_list_item takes (graph, index). - Bulk import: an annotation's link is written to the graph its slots name, and a triple-term statement in a named graph is spooled under that graph (both landed in the default graph); emit_quad_reified_triple is implemented. resolve_object_value keeps main's vector refusals and next's term-table path. - Ledger manager: a store that fails to load fails the load or keeps the reloaded ledger's state (main), over next's load_decoding_root and activation swap rule. - Novelty keeps main's KeptEffects without the retired arena's reifies capture. The pool's resolve_events_at and compaction's split_lifecycles follow fluree_db_core::same_t. - Retired annotation arena files stay deleted. - Tests from main adapted to next: one Fluree per storage directory, async genesis_ledger, storage-namespace content stores, u32 graph ids, a store broken by hiding a dictionary branch (next has no disk cache), a refused import leaving no ledger. next's tests that pinned bulk import refusing @graph and SPARQL's RDF list view now check what main changed them to.
Tests that capture tracing events through a thread-local default subscriber (the fast-path routing stamps
MustFire/MustNotFire, theoverlay_translatespans, the batched-join lane event, and a few in-crate captures) could intermittently see nothing under parallel load. A presence assertion then failed, which is the flake we've been re-running past (jsonld_join_takes_batched_subject_probe_like_sparql,empty_cross_ledger_restrictions_under_default_allow_keep_fast_pathsand others). The quieter half is an absence assertion (MustNotFire) that passed vacuously the same way.The cause is in
tracing-core's callsite interest cache. While only one dispatcher is registered, which a single thread-local capture often is, a callsite's first hit computes its interest from the hitting thread's default alone. When a sibling test's thread with no subscriber hits it first, the callsite is cached as never interesting, and the capturing thread's subscriber never sees that event.The fix is
fluree_test_support::scoped_default(andwith_scoped_default). Once per process, it registers two dispatchers that are nobody's default, answer every callsite withInterest::sometimes()and enable nothing. With two always registered, the single-dispatcher shortcut never applies, and no callsite can be cached as never, so each event reaches whichever subscriber is the current thread's default. Two, not one, so that the gap between one test's capture and the next can't fall back to the shortcut. The floor dispatchers receive no events.span_capture::init_test_tracing/init_info_only_tracinggo through it, which covers the routing stamps in about fifty api test files. The in-crate captures (fluree-db-api'slib.rs,import.rsandbm25_worker.rs,fluree-graph-turtle's splitter,fluree-db-binary-index's dict reader,fluree-db-indexer's GC collector events) and the server's telemetry captures do too.init_test_tracing's narrower fix from32336d21c(a secondNoSubscriberdispatcher plus a rebuild) folds into the helper rather than living beside it.rebuild_interest_cache()workaround drop it. A rebuild only repairs callsites already registered, so it never fully closed the gap.harness_coverage::scoped_subscribers_use_the_floorfails, namingfile:line, on a directsubscriber::set_default(/with_default(, or a builder's.set_default(), in a workspace member'ssrc/ortests/. It's a narrow scan (aused bare name isn't caught), and its doc says so.docs/contributing/tests.md: the "instrumentation tests keep their own binary" rule becomes "install through the helper".Global installs (the CLI, MCP serve, server telemetry, a few
try_initprobe layers in tests, benches) are left as they are; a global default doesn't have this race.Proof.
a_callsite_registered_first_on_another_thread_reaches_the_capturereproduces the mechanism deterministically: another thread with no subscriber hits a fresh callsite first, then the capturing thread hits it. With the floor removed (a bareset_default) it failsleft: 0, right: 1; with it, it passes.grp_querywent from 7 failing runs in 60 to 0 in 60, and the policy cross-ledger repro from 18 in 120 to 0 in 120, with no measurable time cost.span_capture.rswhen that file is changed back totracing::subscriber::set_default.WAL flush counts
it_wal::a_transaction_costs_one_flushfailed the same way under load, counting 15 flushes (and in other runs 2) where it expects 1.fsyncs_issued()counts every flush of the root's log, and the log's background thread flushes on its own schedule: it flushes an append left waiting for 50 ms, and it closes a segment once it's a second old and retires it, flushing every file the segment covered. None of those is the transaction's, but whenever a loaded run's window met one, the test counted it. Nextest's process per test doesn't help here, since it's timing inside one test.The fix is a test hook,
FileStorage::pause_wal_background_for_test, which stops the background thread and waits out a pass already under way, so the count is the transaction's own. Every test that counts a window of flushes on a live log uses it now: the two init_wal, and two influree-db-core'swal_tests(a_commit_costs_one_flush,owners_keep_separate_logs_and_flush_every_write) that had the same exposure. With a 1.2 s delay injected into the window, the three that expect exactly one flush failed before (15, 14 and 9) and pass with the hook;concurrent_ledgers_share_a_flushasserts fewer flushes than commits, which the thread's flushes could only push the wrong way. Under load, 36 runs of theit_walbinary, 12 at a time, went from 14 failures to 0.The hook only exists for tests. It compiles in
fluree-db-core's own tests and under a new, non-defaulttest-hooksfeature, whichfluree-db-apiturns on from its dev-dependencies (the way it already turns onresidency). A normal build of the API or the server resolvesfluree-db-corewithout it, so the background thread there is the same code as onmain.No production behavior change.