Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

test(observability): isolate the wallet paging tests on a private Sentry hub\n\n`paging::a_genuine_wallet_failure_still_pages` asserted one Sentry envelope\nfor a real wallet error and got two, deterministically, under the product\nfeature set — the only set in which the `paging` module compiles, which is\nwhy the contributor default run stays green.\n\n`captured_events_for` used `sentry::init`, which binds the client on the\nhub every test thread's hub is copied from. A sibling test's\n`report_error_or_expected` for the same genuine message, running on another\nthread outside the paging lock, therefore captured into the paging test's\ntransport. Bind the client to a private hub that is current only inside\n`Hub::run` instead: nothing process-global is touched, the sibling's capture\nfalls on a hub with no client, and the serialising lock is no longer needed.\n\nVerified under the product feature set: the full binary passes three parallel\nruns and one serial run; before the change every parallel run failed with\n`left: 2`.\n\nClaude-Session: https://claude.ai/code/session_012jp2WUNkZ8dxDVmDtu3JxX\n

Shanu5c300538b160
diff --git a/tests/observability_wallet_expected_e2e.rs b/tests/observability_wallet_expected_e2e.rs
index 640c33a458..222d21f28d 100644
--- a/tests/observability_wallet_expected_e2e.rs
+++ b/tests/observability_wallet_expected_e2e.rs
@@ -253,20 +253,17 @@ fn reporting_a_genuine_wallet_failure_still_emits_error() {
#[cfg(feature = "crash-reporting")]
mod paging {
use super::*;
-
- /// Drive `report_error_or_expected` against an envelope-capturing Sentry
- /// client and return how many events it actually sent.
+ /// Count the Sentry events one call to `report_error_or_expected` produces.
///
- /// `sentry::init` mutates the process-global hub and cargo runs these
- /// functions on parallel threads, so the critical section is serialized
- /// here rather than by imposing `--test-threads=1` on the whole binary —
- /// the same reasoning, and the same shape, as `observability_smoke.rs`.
+ /// The client is bound to a **private** hub that is current only inside
+ /// [`sentry::Hub::run`]. `sentry::init` instead binds it on the hub every
+ /// test thread's hub is copied from, so while a paging test held a client,
+ /// a sibling test's `report_error_or_expected` on another thread landed in
+ /// this transport too — `left: 2` for a genuine failure, deterministic
+ /// under the product feature set, invisible under the contributor default
+ /// set where this module does not compile. No process-global state is
+ /// touched, so the tests need no serialisation.
fn captured_events_for(message: &str) -> usize {
- static SENTRY_TEST_LOCK: Mutex<()> = Mutex::new(());
- let _guard = SENTRY_TEST_LOCK
- .lock()
- .unwrap_or_else(|poisoned| poisoned.into_inner());
-
let transport = sentry::test::TestTransport::new();
let transport_for_factory = transport.clone();
let options = sentry::ClientOptions {
@@ -281,13 +278,15 @@ mod paging {
sample_rate: 1.0,
..sentry::ClientOptions::default()
};
- let _sentry_guard = sentry::init(options);
-
- report_error_or_expected(message, "rpc", "invoke_method", &[]);
-
- sentry::Hub::current()
- .client()
- .map(|c| c.flush(Some(std::time::Duration::from_secs(2))));
+ let client = Arc::new(sentry::Client::from_config(sentry::apply_defaults(options)));
+ let hub = Arc::new(sentry::Hub::new(
+ Some(Arc::clone(&client)),
+ Arc::new(sentry::Scope::default()),
+ ));
+ sentry::Hub::run(hub, || {
+ report_error_or_expected(message, "rpc", "invoke_method", &[]);
+ });
+ client.flush(Some(std::time::Duration::from_secs(2)));
transport.fetch_and_clear_envelopes().len()
}